jQuery选择器:通过ID解决提交按钮失败 [英] jQuery selector: addressing a submit button by ID fails
本文介绍了jQuery选择器:通过ID解决提交按钮失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
提供一个提交按钮:
<input type="submit" value="Sign Up" name="AddToCart" size="2" id="AddToCart" />
此代码为什么不禁用按钮:
why wouldn't this code disable the button:
$('#AddToCart').attr(disabled, 'disabled');
mny thx
推荐答案
传递给 .attr()
的属性名称必须用引号引起来,像这样:
The attribute name passed to .attr()
needs to be in quotes, like this:
$('#AddToCart').attr('disabled', 'disabled');
//or without quotes, as an object:
$('#AddToCart').attr({ disabled: 'disabled' });
还要确保它正在document.ready
事件处理程序中或元素就绪后的其他地方运行,例如:
Also make sure this is running in a document.ready
event handler, or somewhere else after the element is ready, e.g.:
$(function() {
$('#AddToCart').attr('disabled', 'disabled');
});
这篇关于jQuery选择器:通过ID解决提交按钮失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文