我有一个下拉列表和一个事件 selectedIndexChanged 哪个回发,我希望能够在用户更改下拉列表中的值时向用户显示一条消息,根据消息的输入我将决定是否必须回发还是不是。
显示的消息是您确定吗?如果他选择"is",我会继续回发,如果他说“否”,我会取消回发并分配之前选择的值。
我已经搜索了很多但无法找到解决方案,我想如果有一个 javascipt 函数可以确定是否需要回发,我想这可能会有所帮助
谢谢
最佳答案
// get a reference to the DropDownList
var selectlistId = '<%= ddlYourList.ClientID %>',
selectlist = document.getElementById(selectlistId);
// attach to the onchange event
selectlist.onchange = function() {
// decide whether to execute the __doPostBack event, which submits the
// form back to the server
if(confirm("Are you sure you want to do this?")){
__doPostBack(selectlistId, '');
}
};
关于javascript - asp.net Dropdownlist 条件回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697100/