禁用特定形式的所有输入
我可以获得表单 id,
form_id= $(this).parents('form').attr('id');
我可以禁用/启用所有输入,而
if ($('.basket :input').is(':disabled') == true) {
$('.basket :input').removeAttr('disabled');
$(".basket :input").removeClass('disabled');
$(':radio:not(:checked)').each(function(){
$(this).removeClass('hidden').next('label').removeClass('hidden');
});
} else {
$(".basket :input").attr("disabled", "disabled");
$(".basket :input").addClass('disabled');
$(':radio:not(:checked)').each(function(){
$(this).addClass('hidden').next('label').addClass('hidden');
});
我要做的就是仅禁用 form_id 下的输入元素。我想这可能是因为我不知道如何在 Jquery 中替换变量?
I can get the form id with
form_id= $(this).parents('form').attr('id');
I can disable/enable ALL the inputs with
if ($('.basket :input').is(':disabled') == true) {
$('.basket :input').removeAttr('disabled');
$(".basket :input").removeClass('disabled');
$(':radio:not(:checked)').each(function(){
$(this).removeClass('hidden').next('label').removeClass('hidden');
});
} else {
$(".basket :input").attr("disabled", "disabled");
$(".basket :input").addClass('disabled');
$(':radio:not(:checked)').each(function(){
$(this).addClass('hidden').next('label').addClass('hidden');
});
what I am trying to do is disable only the input elements under form_id. I think it is maybe beacause I do not know how to subsitute variables in Jquery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将 formID 选择器添加到选择器的开头,例如
Add the formID selector to the beginnning of your selectors e.g.
由于性能原因,
我通常不会提倡使用伪选择器,因此如果您愿意,您可以将其替换为离散的 tagName 列表。
What about
I wouldn't usually advocate using pseudo-selectors due to performance, so you could replace that with a discrete tagName list, should you wish.
要禁用 id 为“form_id”的容器内的所有“输入”:
启用 id 为“form_id”的容器内的所有“输入”:
请注意,输入 psuedoselector 不一定仅表示标签。有关详细信息,请参阅此页面。
To disable all "inputs" inside the container with id "form_id":
To enable all "inputs" inside the container with id "form_id":
Notice that the input psuedoselector does not necessarily mean only tags. See this page for more info.
如果我正确地回答了你的问题:试试这个
禁用 form_id 内的所有输入字段:
启用所有元素:
如果您想了解如何从 jquery 获取元素以及 jquery 如何工作:请阅读这篇文章:
http://learningtechstuff.wordpress.com/2011/11 /23/jquery-learning-series-for-beginners
If I am getting your question correctly:try this
To disable all input field inside form_id:
To enable all element:
And if you want to learn How to get element from jquery and how jquery work: please read this article:
http://learningtechstuff.wordpress.com/2011/11/23/jquery-learning-series-for-beginners