【发布时间】:2010-06-08 22:08:34
【问题描述】:
我对 jQuery 还很陌生。我在用户控件中有一个 Jquery 日期选择器。我在日期选择器中添加了一个“禁用”属性。每当我保存页面(具有此用户控件)时,禁用设置为 true 的日期选择器为空。所有其他日期选择器都可以正常保存。
这是我的代码。
ASPX
ASCX
ASCX 代码隐藏
Public Property Disable() As Boolean
Get
Return (txtDate.Disabled = True)
End Get
Set(ByVal bValue As Boolean)
If (bValue = True) Then
txtDate.Attributes.Add("Disabled", "True")
Else
txtDate.Attributes.Remove("Disabled")
End If
End Set
End Property
我的 Jquery
$(document).ready(function() {
$("input[id$=txtDate]").datepicker({ showOn: 'button', buttonImage: '<%=ConfigurationSettings.AppSettings("BASE_DIRECTORY")%>/Images/el-calendar.gif', buttonImageOnly: true });
$("input[id$=txtDate]").mask("99/99/9999", { placeholder: " " });
//Disable datepicker if "disable=true"
$("input[id$=txtDate]").each(function() {
if ($("input[id$=" + this.id + "]").attr("Disabled") == "True") {
$("input[id$=" + this.id + "]").datepicker("disable");
}
else if ($("input[id$=" + this.id + "]").attr("Disabled") == "False") {
$("input[id$=" + this.id + "]").datepicker("enable");
}
});
});
对不起,我不知道如何格式化这里的代码。我为混乱的代码道歉。 谁能告诉我为什么 datepicker 值在禁用时为空,但在其他情况下工作正常? 提前谢谢。
【问题讨论】:
-
这是一个 HTML 的东西——禁用的表单字段不会被浏览器发送到服务器;改为使用只读。
标签: jquery datepicker