如何禁用和启用JavaScript中的下拉列表框? [英] How to disable and enable drop down List box in javascript ?

查看:93
本文介绍了如何禁用和启用JavaScript中的下拉列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

Hello ,

function validateRelationshipGender() {

        var gender, genderForm;
        gender = document.getElementById("NewUser:ContactPersonGender").value;
        genderForm = document.getElementById("NewUser:ContactPersonGender").disabled = true;
        if (gender == "Male" || gender == "Female") {

            genderForm = document.getElementById("NewUser:ContactPersonGender").disabled = false;

        }

    }

推荐答案

我建​​议使用jQuery,它使JavaScipting的编写和读取更加容易:

要使用jQuery禁用控件,请使用attr()函数,将属性作为第一个参数,将值作为第二个参数.

I would recommend using jQuery, it makes JavaScipting easier to write and read:

To disable a control using jQuery use the attr() function passing in the attribute as the first parameter and value as the second.


(" ).attr(" > true );
("#ddlc").attr("disabled", true);



其中ddlc是控件的ID(在我的情况下是ASP.NET,在您的情况下可能是JSF):



where ddlc is the id of the control (which in my case is ASP.NET and in yours probably JSF):

<asp:dropdownlist id="ddlc" runat="server" clientidmode="Static"></asp:dropdownlist>




有关jQuery详细文档,请参考: jQuery [ ^ ]

请让我知道这是否对您不起作用,我将删除此解决方案.




For detailed jQuery documentation refer: jQuery[^]

Please let me know if this doesn''t work for you and I will remove this solution.



这篇关于如何禁用和启用JavaScript中的下拉列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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