当复选框分配有 jQuery 时,勾选不再起作用
我的其中一个页面上的复选框遇到了一个奇怪的问题。基本上,我分配了一些 jQuery(如下),这样当单击它时,下面的字段将填充与上面相同的信息(与计费信息类似)但是,当将此 jQuery 分配给它时,勾号无法显示填写复选框。
我尝试了各种方法来手动勾选复选框,但无济于事,有人可以解释这个问题吗?
$('#sameasbilling').toggle(function() {
//assign value of billing firstname text input to variable 'firstname'
var firstname = $('input[name=billingfirstnames]').val();
//insert value of 'firstname' into delivery text input
$('input[name=deliveryfirstnames]').val(firstname);
$('#sameasbilling').attr("checked", checked);
},function() {
$('input[name=deliveryfirstnames]').val("");
});
我尝试过的 jQuery(加上这两行的许多变体)让自动收报机手动工作如下,但它们都没有工作。
$('#sameasbilling').attr("checked", checked);
$('#sameasbilling').prop("checked", true);
提前致谢。担。
I'm having a strange problem with a checkbox on one of my pages. Basically I have a bit of jQuery ( below ) assigned to it so that when it is clicked the fields below fill up with the same info as above ( same as billing info kinda thing ) However when this jQuery is assigned to it the tick fails to fill the checkbox.
I have tried various methods to get the checkbox to tick manually but to no avail, could anyone shed some light on this problem?
$('#sameasbilling').toggle(function() {
//assign value of billing firstname text input to variable 'firstname'
var firstname = $('input[name=billingfirstnames]').val();
//insert value of 'firstname' into delivery text input
$('input[name=deliveryfirstnames]').val(firstname);
$('#sameasbilling').attr("checked", checked);
},function() {
$('input[name=deliveryfirstnames]').val("");
});
The jQuery I have tried ( plus many variants of those two lines ) to get the ticker to work manually is below, neither of them have worked.
$('#sameasbilling').attr("checked", checked);
$('#sameasbilling').prop("checked", true);
Thanks in advance. Dan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您使用的
toggle()
方法不正确,请改用click()
。试试这个:Your use of the
toggle()
method is incorrect in this instance, useclick()
instead. Try this: