禁用属性可以与隐藏一起使用吗 [英] Does Disabled attribute work with hidden

查看:118
本文介绍了禁用属性可以与隐藏一起使用吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个隐藏字段

<input type = 'hidden' name = "test1" id = "test1" value ="<?php echo $val ?>" >

现在iam通过Jquery应用禁用的属性.禁用属性是否适用于隐藏字段,或者仅适用于输入类型= text

Now iam applying disabled attribiute through Jquery . Will the Disabled attribute work for hidden fields or it will work only for input type = text

$('#test1').attr('disabled','disabled');

if($("#radio_no:checked") && $("#someelement").attr('value')==="abc"){                         
            $("#test1").attr('disabled', true);
            $("#test1").attr('class', 'TextBox');           
}

推荐答案

对于隐藏字段,它可以很好地工作,防止将它们包含在POST表单中.

It will work fine for hidden fields, preventing their inclusion in a form POST.

关于必须将属性设置为字符串"disabled"的奇怪说法是一个神话.将其设置为truefalse以使其清晰.字符串"disabled"起作用是因为它是一个非空字符串,当转换为布尔值时,它是true.如果将其设置为否",假"或绝对不是",则还将禁用输入.

The strange myth about having to set the attribute to the string, "disabled", is, well, a myth. Set it to either true or false to be clear. The string "disabled" works because it's a non-empty string, and when cast to boolean it's true. If you were to set it to "no" or "false" or "absolutely not", you'd also disable the input.

edit —为了清楚起见,请像您在示例中一样设置Disabled属性,除了:

edit — to be clear, set the disabled attribute just as in your example, except:

$('#test1').attr('disabled', true);

再次编辑—对于那些对我的陈述表示反对的人,这些人对我关于如何(使用 JavaScript ,而不是任何页面源语言)如何使用"true"和"false"作为"disabled"属性的陈述表示反对,我建议您 上下文的特定规则就不再重要了.我们在这里讨论的是从JavaScript设置 DOM 属性为已禁用",因此要引用的适当标准是DOM规范.

edit again — and to those misguided people who disagree with my statement about how (in JavaScript, not in any page source language) one should use true and false for the "disabled" attribute, I would direct you to the appropriate section of the W3C DOM Level 1 spec, where the "disabled" attribute is clearly typed as a boolean, not a string. Once the browser has parsed your pristine, standards-compliant source, be it HTML4, XHTML, HTML5, or whatever, the specific rules for that context no longer matter. We're talking about setting the DOM attribute "disabled" from JavaScript here, so the appropriate standard to reference is the DOM spec.

这篇关于禁用属性可以与隐藏一起使用吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆