채택완료
글 수정 시, show hide 초기화가 되는데, 그대로 값 불러오게끔 하려 합니다.
Copy
<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();
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>
write.skin.php에 이 스크립트를 써서 사용하고 있는 상태인데, 글 수정 시 4개의 라디오버튼 선택이 충족 되어있는데, show가 되어있지 않습니다. ㅠㅠ
근데, 라디오버튼 선택을 다른것으로 선택하고 다시 충족하게되면 show가 되어지는데, 글 수정 시, get으로 값을 가져와서 충족이 되어있는 상태이면 show를 하고싶은데, 코드상에 문제가 있을까요?
|
답변 1개 / 댓글 19개
채택된 답변
+20 포인트
.on('change', functionI() ~
은 라디오 버튼 또는 체크박스의 값이 (유저 액션에 의해) 변경되는 이벤트가 발생했을 때만 실행됩니다.
수정화면에서는.. 유저액션 없이 페이지가 로드될 때 수행해주어야 되기 때문에..
해당 부분을 수동으로 호출해주면 됩니다.
Copy
<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>
답변에 대한 댓글 19개
[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]
혹시 이부분도 봐주실 수 있나요? 라디오버튼에 체크가 되어있을 시, 스타일클래스를 넣으려고 하는데 적용이 되지 않아서요 ㅠㅠ
[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]
순간적으로 변하긴하는거같은데,
[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]
이부분을 써서 그런지 서브밋되면 다시 풀려버리네요 ㅠㅠ
<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>
<?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
<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
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>
답변을 작성하려면 로그인이 필요합니다.
$(function(){$("#wr_3").val("<?=$write['wr_3[]']?>");});
이부분이 안먹히는거같아서 스크립트문에 삽입했는데도 먹히질 않네요 ㅠㅠ