我对这段代码感到非常生气:D 我在设置为只读的输入字段中使用 jQuery 日期选择器,并且日期选择器应该在同一页面中出现两次,并且它取决于下拉列表的值。
我使用的语言是 ASP.NET c#:
以下输入文本框位于我的 aspx 页面上:
<asp:TextBox ID="txt_check_chequeDate" runat="server" BorderStyle="Solid"
BorderWidth="2px" Font-Names="Calibri" Style="margin-left: 0px" ClientIDMode="Static" ReadOnly="true"></asp:TextBox>
<tr ID="tr_wire_TransactionDate" runat="server">
<td>
<asp:Label ID="lbl_wire_TransactionDate" runat="server" Font-Names="Calibri"
Text="Transaction Date"></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_wire_chequeDate" runat="server" BorderStyle="Solid"
BorderWidth="2px" ClientIDMode="Static" Font-Names="Calibri"
Style="margin-left: 0px" ReadOnly="true"></asp:TextBox>
</td>
</tr>
我的 jQuery 脚本如下并附有引用文献:
<script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script>
<script src='../Scripts/jquery-1.4.1-vsdoc.js' type='text/javascript'></script>
<script src='../Scripts/jquery.ui.core.js' type='text/javascript'></script>
<script src='../Scripts/jquery.ui.widget.js' type='text/javascript'></script>
<link href='../Styles/jquery.ui.all.css' rel='stylesheet' type='text/css'/>
<link href='../Styles/jquery.ui.datepicker.css' rel='Stylesheet'
type='text/css' />
<script src='../Scripts/jquery.ui.datepicker.js' type='text/javascript'></script>
<script type='text/javascript'>
$(function () {
$('#txt_check_chequeDate').datepicker({ changeYear: true });
});
$(function () {
$('#txt_wire_chequeDate').datepicker({ changeYear: true });
});
当我单击提交按钮时,我通过执行以下命令获得空值:
Debug.WriteLine("on page click value is wire = " + this.txt_wire_chequeDate.Text.Trim());
Debug.WriteLine("on page click value is cheque = " + this.txt_check_chequeDate.Text.Trim());
知道为什么我通过日期选择器获取空日期吗,当我尝试早期时,我仅在一种情况下正确获取了值:(
最佳答案
去掉webform控件的readonly属性,通过javascript设置readonly属性。
<script type='text/javascript'>
$(function () {
$("#txt_check_chequeDate").attr("readonly", true);
$("#txt_wire_chequeDate").attr("readonly", true);
})
</script>
关于javascript - jquery datepicker 和 asp.net c# 空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44988772/