[英]check/uncheck an input(checkbox) php variable
I have the php variable $optquaninp = "<input type=\\"checkbox\\" name=\\"optid".$o['id']."\\" value=\\"1\\"/>";
我有php变量$optquaninp = "<input type=\\"checkbox\\" name=\\"optid".$o['id']."\\" value=\\"1\\"/>";
and I want to set it as checked/unchecked from a script. 我想将其设置为从脚本中选中/未选中。
Specifically, I want to change its state by clicking on a card. 具体来说,我想通过单击卡来更改其状态。 So I applied script below 所以我在下面应用了脚本
<script>
$('.card-deck-wrapper').on('click', function(event) {
var val = "<?php echo $optid.$o['id'] ?>";
document.getElementByName("optid1").checked =false;
});
</script>
It doesn't work! 它不起作用!
Try using jQuery. 尝试使用jQuery。
$('.card-deck-wrapper').on('click', function(event) {
var val = "<?php echo $optid.$o['id'] ?>";
// jQuery 1.6+
// Use the new .prop() method:
$('input[name='+val+']').prop('checked', true);
$('input[name='+val+']').prop('checked', false);
// jQuery 1.5.x and below
// The .prop() method is not available, so you need to use .attr().
$('input[name='+val+']').attr('checked', true);
$('input[name='+val+']').attr('checked', false);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.