带有asp.net选择项更改事件的jquery

带有asp.net选择项更改事件的jquery,jquery,asp.net,Jquery,Asp.net,我有许多下拉列表控件 <asp:DropDownList ID="ddlusertype" runat="server" AutoPostBack="True"> <asp:ListItem>---Select User---</asp:ListItem> <asp:ListItem>Patient</asp:ListItem> <asp:ListItem>Doctor</asp:ListIte

我有许多下拉列表控件

<asp:DropDownList ID="ddlusertype" runat="server" AutoPostBack="True">
    <asp:ListItem>---Select User---</asp:ListItem>
    <asp:ListItem>Patient</asp:ListItem>
    <asp:ListItem>Doctor</asp:ListItem>
    <asp:ListItem>Pharmasits</asp:ListItem>
    <asp:ListItem>Lab Assistance</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="ddlmaritalstatus" runat="server" CssClass="chkbox">
    <asp:ListItem>---Select Status---</asp:ListItem>
    <asp:ListItem>Married</asp:ListItem>
    <asp:ListItem>Unmarried</asp:ListItem>
</asp:DropDownList>

---选择用户---
病人
医生
药剂师
实验室协助
---选择状态---
已婚的
未婚的
所以这里我想用jquery在ddlusertype处理选中的条目更改事件,所以我用jquery

<script type="text/javascript">

$(document).ready(function () {
    $('input:text').each(function () {
        $(this).attr('disabled', true);
    });
    $("select").change(function () {
        alert(this.value);
        if (this.value != "User Select") {
            alert(this.value);
            $('input:text').each(function () {
                $(this).attr('disabled', false);
            });

        }
        if (this.value == "User Select") {
            $('input:text').each(function () {
                $(this).attr('disabled', true);
            });
        }
    })
});

$(文档).ready(函数(){
$('input:text')。每个(函数(){
$(this.attr('disabled',true);
});
$(“选择”).change(函数(){
警报(该值);
如果(this.value!=“用户选择”){
警报(该值);
$('input:text')。每个(函数(){
$(this.attr('disabled',false);
});
}
如果(this.value==“用户选择”){
$('input:text')。每个(函数(){
$(this.attr('disabled',true);
});
}
})
});

问题是,当我再次选择“选择用户”时,事件无法启动。。。所以请帮帮我。 第二个问题是我无法区分哪个ddl事件是由#IdName发生的。



更改AutoPostBack=“False”,否则页面将重新加载,并且您的函数将不会被调用

出于区分的目的,请使用Jquery选择器单独运行下拉更改事件。请参阅:


$(文档).ready(函数(){
$('input:text')。每个(函数(){
$(this.attr('disabled',true);
});
$(“[id$='ddlusertype']”)。更改(函数(){
警报(该值);
//你在这里工作吗
})
$(“[id$='ddlmaritalstatus']”)。更改(函数(){
警报(该值);
//你在这里工作吗
})
});

对于第一个问题,jquery脚本工作正常。请参见jsfiddler:

无法更改选项的值,我这样更改值,单击ddl的屏蔽箭头并单击编辑时间,然后将值更改为0、1、2等,然后构建项目并刷新网页,当我看到查看页面源值未更改时,请帮助我当你建立你的项目,然后所有的dll将重新编译,所有的会话和视图将销毁。我不明白复制的确切步骤,但通常在构建项目时,所有控件都会错过其最后状态。好的,那么我如何更改ddl选项的值,它始终默认值是它的文本,例如ddlusertype,patient的值将始终是patient,是否将其更改为其他值。请在firebug或google chrome的inspect元素选项中查看控制台窗口。也许你会在jquery代码中看到任何错误。兄弟,我是asp.net Thanx的新手,需要帮助:它能解决你的问题吗?我不知道自动回邮和viewstate等。。。但是jquery中的问题我认为是这样的……如果您将AutoPostBack更改为“False”,事件将被触发。如果您想选择dropdownlistbyid,请尝试添加这个clientmode=“Static”兄弟问题解决了,但另一个问题是,当我们向ddl添加选项时,此时会生成默认值,其中包含option的文本。所以我想更改默认值。但这是无法改变的。
<asp:DropDownList ID="ddlusertype" runat="server" AutoPostBack="True" ClientIDMode="Static">
<script type="text/javascript">

$(document).ready(function () {
    $('input:text').each(function () {
        $(this).attr('disabled', true);
    });
    $("[id$='ddlusertype']").change(function () {
        alert(this.value);
        //do your work here
    })

   $("[id$='ddlmaritalstatus']").change(function () {
        alert(this.value);
        //do your work here
    })
});