jQuery .attr(“disabled”,“disabled”)在Chrome中无法使用 [英] jQuery .attr("disabled", "disabled") not working in Chrome
问题描述
不确定为什么这不工作。
Not sure why this isn't working.
当用户点击我的应用程序的修改按钮时,已禁用的文本字段变为可编辑:
When people click the 'edit' button of my application, the disabled textfields become editable:
$("#bewerken").click(function(e) {
$("input[disabled='disabled']").removeAttr('disabled');
});
然后我想在用户保存时再次禁用textfields;我有这个代码绑定到我的保存按钮:
I then want to disable the textfields again when the user saves; I have this code bound to my save button:
$("#save_school_changes").click(function(e) {
//stuff
$.ajax({
type: "POST",
url: "/school/save_changes",
data: { //stuff },
success: function(data)
{
$("#feedback_top").html("<p>" + data['message'] + "</p>").slideDown('slow').delay(2000).slideUp();
$("input[type='text']").attr('disabled', 'disabled');
}
});
e.preventDefault();
});
据我所知,这应该再次禁用textfields。但是,这似乎不工作在Chrome。它在Firefox中工作。我没有机会在IE或Safari测试。有没有什么办法使这项工作在Chrome中?非常感谢!
As far as I know, this should disable the textfields again. However, this does not seem to be working in Chrome. It does work in Firefox. I haven't had the chance to test in IE or Safari yet. Is there any way to make this work in Chrome aswell? Thanks a lot!
推荐答案
如果您使用jQuery< 1.6
这样做:
If you are using jQuery < 1.6 do this:
jQuery("input[type='text']").attr("disabled", 'disabled');
如果您使用的是jQuery 1.6 +:
If you are using jQuery 1.6+:
jQuery("input[type='text']").prop("disabled", true);
See this question: .prop() vs .attr() for references why.
或者你可以试试这个:
$('input:text').attr("disabled", 'disabled');
这篇关于jQuery .attr(“disabled”,“disabled”)在Chrome中无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!