禁用按钮在点击上工作
$(document).ready(function() {
$("#FieldsetID").each(function() {
$('.Isubmit').attr('disabled', 'disabled');
});
});
该按钮显示为禁用,但当我点击它的doign动作?禁用按钮在点击上工作
是我做错了什么?
谢谢
由于某些原因,当您单击禁用的提交按钮时,IE不会阻止该事件冒泡。
我假设你有一些其他的事件处理程序,因此被触发的祖先。
在那个祖先的事件处理程序中,它看起来像您需要测试以查看是否单击了该按钮并且该按钮是否被禁用。如果是这样,你会return false;
阻止代码运行,或发生提交,或任何其他。
// Not sure if this is the right event, but you get the idea
$(someSelector).click(function(event) {
var $target = $(event.target);
// check to see if the submit was clicked
// and if it is disabled, and if so,
// return false
if($target.is(':submit:disabled')) {
return false;
}
});
我不认为你可以在一个独特的元素上运行.each()函数。它是独一无二的,因为您使用的是#id选择器。
你只需要做到这一点:
$(document).ready(function() {
$('#FieldsetID .Isubmit').attr('disabled', 'disabled');
});
现在的按钮不应该点击。
他说按钮已经显示为禁用,所以我不认为这是问题所在。另外,尽管你不应该在id选择器上运行每个选项,但是没有人说你不能,所以尽管效率很低,他的代码仍然可以工作。 – Mark 2010-06-24 17:59:23
@Mark - +1什么都没有(除了最佳实践)防止一个人循环播放一个项目的数组。 – user113716 2010-06-24 18:02:46
Altough未经测试,我认为当你通过id选择元素时,你不需要使用每个元素,因为它返回一个元素,而当你选择使用类时你必须使用每个元素,尝试使用每个禁用选择器看看。
http://forum.jquery.com/topic/disable-enable-button-in-form
试试这个来启用它。再次
$(document).ready(function(){
$("input[type=submit]").attr("disabled", "disabled");
if ($('#nome').is(":empty")) {
alert ("verdadeiro");
}
else {
alert ("entrou no if");
$("input[type=submit]").removeAttr("disabled");
}
});
好一个最简单的方法就是找如果点击按钮已禁用类,如果它有返回false,例如:
$('.button1').click(function() {
if ($(this).hasClass('disabled')) {
return false;
} else {
//do whatever you want when element is clicked
}
});
你在代码绑定到该按钮,其他地方的一些事件? – Mark 2010-06-24 17:50:24