글 수정 시, show hide 초기화가 되는데, 그대로 값 불러오게끔 하려 합니다. 채택완료
qoqofh
4년 전
조회 2,731
</p>
<p><script>
$(function(){$("#wr_3").val("<?=$write['wr_3[]']?>");});
$("tr.aa").hide();
$('input[name=wr_1], input[name=wr_2], input[name=wr_4], input[name=wr_7], select[name=wr_3]').on('change', function() {
var wr_1 = $('input[name=wr_1]:checked').val();
var wr_2 = $('input[name=wr_2]:checked').val();
var wr_4 = $('input[name=wr_4]:checked').val();
var wr_7 = $('input[name=wr_7]:checked').val();</p>
<p> if (wr_1 == "a1" && wr_2 == "s1" && wr_4 == "d1" && wr_7 == "f1") {
$('tr.sel1111').show();
$('tr.sel1111').siblings("tr.aa").hide();
}
else if (wr_1 == "a1" && wr_2 == "s1" && wr_4 == "d1" && wr_7 == "f2") {
$('tr.sel1112').show();
$('tr.sel1112').siblings("tr.aa").hide();
}
else {
$('tr.aa').hide();
}
});
</script></p>
<p>
write.skin.php에 이 스크립트를 써서 사용하고 있는 상태인데, 글 수정 시 4개의 라디오버튼 선택이 충족 되어있는데, show가 되어있지 않습니다. ㅠㅠ
근데, 라디오버튼 선택을 다른것으로 선택하고 다시 충족하게되면 show가 되어지는데, 글 수정 시, get으로 값을 가져와서 충족이 되어있는 상태이면 show를 하고싶은데, 코드상에 문제가 있을까요?
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
마르스컴퍼니
Expert
4년 전
.on('change', functionI() ~
은 라디오 버튼 또는 체크박스의 값이 (유저 액션에 의해) 변경되는 이벤트가 발생했을 때만 실행됩니다.
수정화면에서는.. 유저액션 없이 페이지가 로드될 때 수행해주어야 되기 때문에..
해당 부분을 수동으로 호출해주면 됩니다.
</p>
<p><script>
$(function(){$("#wr_3").val("<?=$write['wr_3[]']?>");});
$("tr.aa").hide();
$('input[name=wr_1], input[name=wr_2], input[name=wr_4], input[name=wr_7], select[name=wr_3]').on('change', function() {
change_action(); // 별도 함수화 처리
});
function change_action() {
var wr_1 = $('input[name=wr_1]:checked').val();
var wr_2 = $('input[name=wr_2]:checked').val();
var wr_4 = $('input[name=wr_4]:checked').val();
var wr_7 = $('input[name=wr_7]:checked').val();
if (wr_1 == "a1" && wr_2 == "s1" && wr_4 == "d1" && wr_7 == "f1") {
$('tr.sel1111').show();
$('tr.sel1111').siblings("tr.aa").hide();
}
else if (wr_1 == "a1" && wr_2 == "s1" && wr_4 == "d1" && wr_7 == "f2") {
$('tr.sel1112').show();
$('tr.sel1112').siblings("tr.aa").hide();
}
else {
$('tr.aa').hide();
}
}
<?php if ($w == 'u') { ?>
change_action(); // 수정시에는 수동으로 직접 호출
<?php } ?>
</script></p>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 19개
q
qoqofh
4년 전
�
마르스컴퍼니
4년 전
$(function() {
$("#wr_3").val("<?php echo $write['wr_3'] ?>");
});
$("#wr_3").val("<?php echo $write['wr_3'] ?>");
});
q
qoqofh
4년 전
[code]
<script>
$(document).ready(function(){
$("#bo_list .srch_tbl tr label input[type='radio']").change(function(){
if($("#bo_list .srch_tbl tr label input[type='radio']").is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
</script>
[/code]
혹시 이부분도 봐주실 수 있나요? 라디오버튼에 체크가 되어있을 시, 스타일클래스를 넣으려고 하는데 적용이 되지 않아서요 ㅠㅠ
<script>
$(document).ready(function(){
$("#bo_list .srch_tbl tr label input[type='radio']").change(function(){
if($("#bo_list .srch_tbl tr label input[type='radio']").is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
</script>
[/code]
혹시 이부분도 봐주실 수 있나요? 라디오버튼에 체크가 되어있을 시, 스타일클래스를 넣으려고 하는데 적용이 되지 않아서요 ㅠㅠ
�
마르스컴퍼니
4년 전
[code]
<script>
$(function() {
$("#bo_list .srch_tbl input[type='radio']").on('change', function() {
if ($(this).is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
</script>
[/code]
<script>
$(function() {
$("#bo_list .srch_tbl input[type='radio']").on('change', function() {
if ($(this).is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
</script>
[/code]
q
qoqofh
4년 전
순간적으로 변하긴하는거같은데,
[code]
<script>
$('input[name=wr_1], input[name=wr_2], select[name=wr_3], input[name=wr_4], input[name=wr_7], select[name=sca], input[name=sca]').on('change', function() {
this.form.submit();
});
</script>
[/code]
이부분을 써서 그런지 서브밋되면 다시 풀려버리네요 ㅠㅠ
[code]
<script>
$('input[name=wr_1], input[name=wr_2], select[name=wr_3], input[name=wr_4], input[name=wr_7], select[name=sca], input[name=sca]').on('change', function() {
this.form.submit();
});
</script>
[/code]
이부분을 써서 그런지 서브밋되면 다시 풀려버리네요 ㅠㅠ
�
마르스컴퍼니
4년 전
on('change', ~
는 유저 액션으로 라디오 값이 변경될 때만 실행합니다.
서브밋되면 페이지가 새로 로딩되기 때문에..
유저 액션이 없는 경우에는 실행되지 않습니다.
는 유저 액션으로 라디오 값이 변경될 때만 실행합니다.
서브밋되면 페이지가 새로 로딩되기 때문에..
유저 액션이 없는 경우에는 실행되지 않습니다.
q
qoqofh
4년 전
아 그러면 체크가 되어있는 상태일때 배경색을 변경하려면 어떻게 해야하죠 ㅠㅠ?
q
qoqofh
4년 전
[code]
#bo_list .srch_tbl label input[type='radio']:checked ~ label {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
[/code]
css로 구현하려하는데, 인풋이 라벨 안에 있다보니까.... 연산자를 어떻게 사용해야할지를 모르겠네요 ㅠㅠ
#bo_list .srch_tbl label input[type='radio']:checked ~ label {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
[/code]
css로 구현하려하는데, 인풋이 라벨 안에 있다보니까.... 연산자를 어떻게 사용해야할지를 모르겠네요 ㅠㅠ
�
마르스컴퍼니
4년 전
<script>
$(function() {
$("#bo_list .srch_tbl input[type='radio']").on('change', function() {
if ($(this).is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
<?php if ($w == 'u') { ?>
$("#bo_list .srch_tbl input[type='radio'][value='<?php echo $write['wr_100'] ?>']").prop('checked', true);
<?php } ?>
</script>
$(function() {
$("#bo_list .srch_tbl input[type='radio']").on('change', function() {
if ($(this).is(":checked")){
$(this).parent().addClass('checked');
} else {
$(this).parent().siblings().removeClass('checked');
}
});
});
<?php if ($w == 'u') { ?>
$("#bo_list .srch_tbl input[type='radio'][value='<?php echo $write['wr_100'] ?>']").prop('checked', true);
<?php } ?>
</script>
q
qoqofh
4년 전
정말 고생해서 답변주셨는데 ㅠㅠ 적용이 되지 않네요 ㅠㅠ
�
마르스컴퍼니
4년 전
<?php if ($w == 'u') { ?>
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='<?php echo $write['wr_100'] ?>']").prop('checked', true).trigger('change');
});
<?php } ?>
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='1']").prop('checked', true);
});
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='1']").prop('checked', true).trigger('change');
});
페이지가 로딩될 때 value 가 1인 항목으로 체크하라는 스크립트인데.. 이런 코드로 테스트를 해볼 수 있습니다. https://stackoverflow.com/a/4618748
https://m.blog.naver.com/PostView.nhn?blogId=doryjj&logNo=199027914
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='<?php echo $write['wr_100'] ?>']").prop('checked', true).trigger('change');
});
<?php } ?>
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='1']").prop('checked', true);
});
$(function() {
$("#bo_list .srch_tbl input[type='radio'][value='1']").prop('checked', true).trigger('change');
});
페이지가 로딩될 때 value 가 1인 항목으로 체크하라는 스크립트인데.. 이런 코드로 테스트를 해볼 수 있습니다. https://stackoverflow.com/a/4618748
https://m.blog.naver.com/PostView.nhn?blogId=doryjj&logNo=199027914
q
qoqofh
4년 전
너무 감사드려요 ㅠㅠ 암만봐도 해결은 되지 않았지만 ㅠㅠ 정말 감사드립니다 ㅎ
[code] #bo_list .srch_tbl label input[type='radio']:checked [/code]
이거를 어찌어찌 응용해서 하면 될 것 같긴한데,,,,, 인풋이 라벨 안에 있으니 참 답답하네요 ㅠㅠ
[code] #bo_list .srch_tbl label input[type='radio']:checked [/code]
이거를 어찌어찌 응용해서 하면 될 것 같긴한데,,,,, 인풋이 라벨 안에 있으니 참 답답하네요 ㅠㅠ
�
마르스컴퍼니
4년 전
<label><input type="radio" name="wr_1" value="1" <?php echo $write['wr_1'] == "1" ? 'checked'
: '' ?>></label>
<label><input type="radio" name="wr_1" value="2" <?php echo $write['wr_1'] == "2" ? 'checked' : '' ?>></label>
<label><input type="radio" name="wr_1" value="3" <?php echo $write['wr_1'] == "3" ? 'checked' : '' ?>></label>
http://www.gnuwiz.com/bbs/board.php?bo_table=board_tip&wr_id=16
: '' ?>></label>
<label><input type="radio" name="wr_1" value="2" <?php echo $write['wr_1'] == "2" ? 'checked' : '' ?>></label>
<label><input type="radio" name="wr_1" value="3" <?php echo $write['wr_1'] == "3" ? 'checked' : '' ?>></label>
http://www.gnuwiz.com/bbs/board.php?bo_table=board_tip&wr_id=16
q
qoqofh
4년 전
진짜공부 많이해야할거같아요 ㅠㅠ 해결방안이 도무지 안나오네요 ㅠㅠ ㅎㅎ 도움주셔서 감사합니다 ㅎ
�
마르스컴퍼니
4년 전
[code]
#bo_list .srch_tbl input[type='radio']:checked ~ * {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
[/code]
https://stackoverflow.com/a/20547506
https://jsfiddle.net/dmpbn123/
#bo_list .srch_tbl input[type='radio']:checked ~ * {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
[/code]
https://stackoverflow.com/a/20547506
https://jsfiddle.net/dmpbn123/
q
qoqofh
4년 전
[code]
#bo_list .srch_tbl tr label input[type='radio']:checked ~ * {
background: #5e7aa0;
font-weight: 500;
color: #fff;
[/code]
이렇게 사용을 해보았는데 안변하길래, 리플래시때문인가 해서 리플래시 되는 부분을 삭제하고했는데도 먹통이네요 ㅠㅠ
#bo_list .srch_tbl tr label input[type='radio']:checked ~ * {
background: #5e7aa0;
font-weight: 500;
color: #fff;
[/code]
이렇게 사용을 해보았는데 안변하길래, 리플래시때문인가 해서 리플래시 되는 부분을 삭제하고했는데도 먹통이네요 ㅠㅠ
q
qoqofh
4년 전
어... 스펜으로 감싸니까 뭔가 되는느낌인데, ...ㅋㅋ 라벨 전체 색상이 바껴야하는데 스펜 영역만 변경이 되버리니 ㅠㅠ
�
마르스컴퍼니
4년 전
https://jsfiddle.net/fLd1b0m2/
or
<label><input type="radio" name="wr_1" value="1" <?php echo $write['wr_1'] == "1" ? 'checked'
: '' ?>></label>
<label><input type="radio" name="wr_1" value="2" <?php echo $write['wr_1'] == "2" ? 'checked' : '' ?>></label>
<label><input type="radio" name="wr_1" value="3" <?php echo $write['wr_1'] == "3" ? 'checked' : '' ?>></label>
<script>
$('input[name=wr_1]:checked').parent().addClass('checked');
</script>
<style>
#bo_list .srch_tbl label.checked {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
</style>
or
<label><input type="radio" name="wr_1" value="1" <?php echo $write['wr_1'] == "1" ? 'checked'
: '' ?>></label>
<label><input type="radio" name="wr_1" value="2" <?php echo $write['wr_1'] == "2" ? 'checked' : '' ?>></label>
<label><input type="radio" name="wr_1" value="3" <?php echo $write['wr_1'] == "3" ? 'checked' : '' ?>></label>
<script>
$('input[name=wr_1]:checked').parent().addClass('checked');
</script>
<style>
#bo_list .srch_tbl label.checked {
background: #5e7aa0;
font-weight: 500;
color: #fff;
}
</style>
q
qoqofh
4년 전
아저도 어제 새벽에 여러가지 방법으로 해서 해봤는데, 말씀주신 내용처럼 하니 진행되었어요 ㅎㅎ 감사합니다 ㅎ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
$(function(){$("#wr_3").val("<?=$write['wr_3[]']?>");});
이부분이 안먹히는거같아서 스크립트문에 삽입했는데도 먹히질 않네요 ㅠㅠ