当我单击 anchor 标记时,其中的单选按钮必须标记为选中。数据是通过循环传递的,因此数据量很大。这是我的代码:
<a class="toggleanchor sectionsdiv accordion-toggle <?php if($i!=1){ ?> collapsed <?php } ?>" data-toggle="collapse" data-parent="#accordion" href="#collapseOne<?=$i;?>">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-group col-md-4 col-sm-4" style="padding:0;">
<div class="checkbox checkreward">
<label>
<input type="radio" name="radio" <?php if($i==1){ ?> checked <?php } ?> class="form-control radio-height" id="radioid<?=$z;?>" value="<?=$reward['amt'];?>"/> $<?=$reward['amt'];?>
<input type="hidden" id="giftval-<?=$z;?>" value="<?= ucwords($reward['gift']);?>"/>
</label>
</div>
</div>
<div id="hight-light<?=$z;?>" class="col-md-8 col-sm-8 textreward">
<h2><?= ucwords($reward['entry']);?></h2>
<h4 class="text-uppercase text-white">
<b><?=$reward['sup'];?></b>
</h4>
</div><!--.col1 text-center-->
</div>
<br clear="all" />
</a>
这个 anchor 在循环中重复,所以数据每次都会改变。我怎样才能让它发挥作用?我尝试了不同的代码但无法让它工作。喜欢
$(".toggleanchor").click(function(event) {
$(radio).attr("checked", true);
});
最佳答案
请使用这个...
$(".toggleanchor").click(function(event) {
$(this).find('input[type="radio"]').prop("checked", true);
});
关于javascript - 单击 anchor 标记后将单选按钮标记为选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31406481/