I have the php variable $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.
$('.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);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.