使用JQuery禁用时,下拉列表所选值在PostBack上重置
Drop Down List Selected Value Gets Reset On PostBack When Getting Disabled With JQuery
我有这样的问题,如果我在下拉列表的.change事件上使用JQuery禁用控件,则控件将重置为默认状态。
我有以下代码:
ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script type='text/javascript' src="jquery-1.11.0.min.js"></script>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="1">Item1</asp:ListItem>
<asp:ListItem Value="2">Item2</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
<script type="text/javascript">
$("#DropDownList1").change(function () {
$("#DropDownList1").attr("disabled", "disabled");
});
</script>
</html>
代码背后:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
因此,使用该代码,如果将所选项目从DropDownList1
切换到PostBack,它将重置为默认状态。如果Jquery没有禁用该控件,则不会重置该控件。
如何使其在禁用时在PostBack上保持其价值?
您可以删除Autopostback="True"
,这样就不会发生回发。。
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">Item1</asp:ListItem>
<asp:ListItem Value="2">Item2</asp:ListItem>
</asp:DropDownList>
每当您在更改下拉项时必须对代码执行某些操作时,就会设置Autopostback="True"
。。
尝试这样禁用。。
$("#DropDownList1").attr("disabled", true);
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 如何使用jQuery自动打开页面上的所有链接
- 如何使用jquery在填充自动完成的值后使文本框只读
- jQuery:循环一个具有不同超时值的循环
- 用程序搜索JQuery数据表中的文本
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jQuery匹配JSON对象的部分文本
- Jquery POST未填充数组
- JQuery使计数器每次更改时都会增加
- 如何在Angular2中使用jQuery插件
- 提高JQuery的性能
- 无法在通过jQuery的ajax加载的页面中执行javascript
- JQuery合并了keyup和focusout两个函数
- 如何使用jQuery选择下拉列表的值
- 将PHP变量传递给jQuery时遇到问题
- jQuery UI自动完成突然停止工作
- 剑道网格jQuery动画()问题
- 如何使用jQuery UI对话框在确认后触发LinkButton Postback
- 保持标签的位置,而PostBack c# jQuery 1.10
- 使用JQuery禁用时,下拉列表所选值在PostBack上重置