选中/取消选中输入(复选框)PHP 变量



我有php变量$optquaninp = "<input type="checkbox" name="optid".$o['id']."" value="1"/>";我想将其设置为从脚本中选中/未选中。

具体来说,我想通过单击卡片来更改其状态。所以我应用了下面的脚本

<script>
$('.card-deck-wrapper').on('click', function(event) {
var val = "<?php echo $optid.$o['id'] ?>";
document.getElementByName("optid1").checked =false;
});
</script>

不行!

尝试使用 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);
});

最新更新