有没有办法一次禁用一堆表单元素? [英] Is there any way to disable a bunch of form elements at once?
问题描述
我想根据某些条件禁用部分HTML表单元素。这似乎是做到这一点的理想方式:
< fieldset disabled>
< input value =one/>
< input value =two/>
< / fieldset>
现在,这两个输入被禁用。但是,这似乎完全在IE8上。输入出现禁用,但我仍然可以输入它们。
小提琴(不像IE8中的JsFiddle实际上是 )
是否有针对此问题的跨浏览器解决方案,向每个表单元素添加 disabled (这会使我的脚本复杂化)。我可能会做一些棘手的事情,比如在jQuery中选择< fieldset>
,然后 .each()
表单元素并禁用它们 - 但是,实际上我使用Knockout绑定来设置 disabled
属性,所以真的没有地方可以添加这样的代码。我最后的手段是使用一个自定义的Knockout绑定来禁用所有的孩子,但是很感谢。
总之:否即可。造成这种情况的原因是因为IE8缺少支持,字段集元素中的
禁用
属性。
在IE7和IE8中,该属性只会禁用
<
恐怕您应该寻找像其他用户的答案或自己的自定义绑定一样的自定义解决方案。 / p>
I'd like to disable a section of HTML form elements depending on some conditions. This seems to be the ideal way to do that:
<fieldset disabled>
<input value="one" />
<input value="two" />
</fieldset>
Now, those two inputs are disabled. However, this seems to be totally borked on IE8. The inputs appear disabled but I can still type in them.
Fiddle (Not as if JsFiddle actually works in IE8)
Is there a cross-browser solution for this problem, without adding disabled to every form element (which would complicate my script). I could probably do something tricky like select the <fieldset>
in jQuery, then .each()
through all the form elements and disable them - however, I'm actually setting the disabled
attribute using a Knockout binding so there's really no place to add such code. My last resort is to use a custom Knockout binding that disables all the children too, but le sigh.
In short: No. The reason behind this is because the lack of support in IE8 and the disabled
attribute on the fieldset
element.
In IE7 and IE8, the attribute only disables form elements in the < legend >.
I'm afraid you should look for a custom solution like the answers from other users / your own custom binding.
这篇关于有没有办法一次禁用一堆表单元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!