gpt4 book ai didi

javascript - 单击模式“同意”按钮时未选中复选框

转载 作者:行者123 更新时间:2023-12-01 02:05:21 28 4
gpt4 key购买 nike

我有一个带有链接标记的复选框。单击链接标签时,我的模式打开。单击按钮然后选中复选框时我有模式

<div class="form-check form-check-radios">
<label class="form-check-label">
<input class="form-check-input number" type="checkbox" name="" value="" id="termsChk">I agree with
<span class="form-check-sign"></span>
</label> <a href="#termsModal" data-toggle="modal">"Terms and Condition"</a>
</div>

我希望当我单击“同意”按钮时,然后选中复选框。单击同意按钮时,我的模式复选框中的问题未选中

这是我的模态代码

  <div class="modal fade" id="termsModal" tabindex="-1" role="dialog" aria- 
labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Terms and Conditions</h4>
</div>
<div class="modal-body" id="modalBody1" style="overflow-y: scroll; max-height:70%; margin-top: 20px; margin-bottom:20px;">
<p style="text-align:justify;" id="modalTerms">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non ipsum at magna finibus rhoncus a vitae leo. Phasellus id nibh luctus, gravida elit pellentesque, consectetur sem. Nulla fringilla, nulla et egestas rhoncus, sem risus iaculis neque, eget aliquam mauris erat vitae nulla. Vivamus placerat est lectus, ac molestie orci tincidunt a. Aliquam ac viverra sapien, sed vestibulum ex. Fusce malesuada ut arcu at porttitor. Cras suscipit leo vel varius venenatis. Nullam aliquam non elit a lacinia.

Morbi vulputate, purus in dictum luctus, urna sapien auctor neque, at venenatis turpis justo nec neque. Etiam a tortor turpis. Quisque auctor nec neque sed viverra. Maecenas sit amet nisl risus. Aenean ut felis eu diam vehicula porttitor. Donec eget nunc est. Nunc porttitor felis sem, eu tristique erat auctor et. Donec sed magna nunc. Nulla pretium orci quis sem dictum volutpat.

Morbi vulputate, purus in dictum luctus, urna sapien auctor neque, at venenatis turpis justo nec neque. Etiam a tortor turpis. Quisque auctor nec neque sed viverra. Maecenas sit amet nisl risus. Aenean ut felis eu diam vehicula porttitor. Donec eget nunc est. Nunc porttitor felis sem, eu tristique erat auctor et. Donec sed magna nunc. Nulla pretium orci quis sem dictum volutpat.

Morbi vulputate, purus in dictum luctus, urna sapien auctor neque, at venenatis turpis justo nec neque. Etiam a tortor turpis. Quisque auctor nec neque sed viverra. Maecenas sit amet nisl risus. Aenean ut felis eu diam vehicula porttitor. Donec eget nunc est. Nunc porttitor felis sem, eu tristique erat auctor et. Donec sed magna nunc. Nulla pretium orci quis sem dictum volutpat.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button class="btn btn-primary" data-dismiss="modal" disabled aria-hidden="true" id="agreeBtn">Agree</button>
</div>
</div>

这是 jquery 代码

$('#agreeBtn').click(function(){
alert("btn click");
$("#termsChk").attr('checked');
});

提前致谢

最佳答案

在您的 jquery 代码中,attr() 需要 2 个参数 - 属性及其值:

 $('#agreeBtn').click(function(){
alert("btn click");
$('#termsChk').attr('checked', true);
});

有关使用 jquery 设置复选框值的更多方法,请参阅此 SO answer

关于javascript - 单击模式“同意”按钮时未选中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50150128/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com