常用控件js示例

1.下拉框索引改变触发函数

 $("#<%=ddlCapacityName.ClientID %>").live("change", function() {
             function ShowProductLevelType() {
            var cName = $("#<%=ddlCapacityName.ClientID %>").val();
            if (cName == "15" || cName == "31") {
                $("#trProductLevelType").show();
                $("#<%=ddlProductLevelTypeID.ClientID %>").attr("req", "1");
            }
            else {
                $("#trProductLevelType").hide();
                $("#<%=ddlProductLevelTypeID.ClientID %>").removeAttr("req");
            }
        }        })


2.js获取下拉框选中值

 var specialtySelect = document.getElementById("<%=ddlSpecialtyName.ClientID %>");
 if (specialtySelect.options[specialtySelect.selectedIndex].value == "") {
                    alert("-请选择专业");
                    return false;
                }


 3.下拉框索引改变控制控件可用不可用

function InitCustomerPlugin() {
            ContractDDLSpeciality();
        }
        $("#<%=ddlCapacityName.ClientID %>").live("change", function () {

            ContractDDLSpeciality();
        })

        function ContractDDLSpeciality() {
            var capacitySelect = document.getElementById("<%=ddlCapacityName.ClientID %>");
            var capacity = capacitySelect.options[capacitySelect.selectedIndex].innerText;
            if (capacity.indexOf("设计总工程师") >= 0) {
                $("#<%=ddlSpecialtyName.ClientID %>").attr("disabled", "disabled");
            }
            else {
                $("#<%=ddlSpecialtyName.ClientID %>").disabled=true;
            }
        }


 4.获取单选框选中的值

 var item = $("input[@name='radlContractTypeName']:checked").val();  //jquery 是1.3版本以下的写法

 var item = $("input[name='radlContractTypeName']:checked").val(); //jquery 是1.3版本以上的写法

你可能感兴趣的:(常用控件js示例)