我正在为我的网页使用JQUERY UI。我正在尝试使用datepicker控件。问题是jquery函数没有采用文本框ID。当我将内容占位符id与textbox id连接起来时,它正在工作。
<asp:Content ID="PassportContent" ContentPlaceHolderID="CPH001" runat="server">
<div class="form-group">
<label>Date Of Birth</label>
<asp:TextBox ID="datepicker" runat="server" CssClass="txt-control"></asp:TextBox>
</div>
</asp:Content>
实际jquery代码
<script src="../jquery/external/jquery/jquery.js"></script>
<script src="../jquery/jquery-ui.min.js"></script>
<script>
$(function () {
$("#datepicker").datepicker();
});
</script>
工作jquery代码
<script>
$(function () {
var temp = document.getElementById('<%= datepicker.ClientID %>').value;
alert(temp);
$("#CPH001_datepicker").datepicker();
});
</script>
当我在论坛中搜索大多数建议使用document.getElementById
的解决方案时,我尝试使用&gt;&gt;
document.getElementById('<%= datepicker.ClientID %>').value
;但警告框显示为NULL。
根据建议,我使用了$("[id$=datepicker]").datepicker();
。它的工作原理我得到了datepicker。但我无法更改日期格式并限制日期范围。请建议。
<script>
$(function () {
$("[id$=datepicker]").datepicker();
$("[id$=datepicker]").datepicker({ dateFormat: 'ISO 8601 - yy-mm-dd' }); // not working
});
// not working
$("#format").change(function () { $("[id$=datepicker]").datepicker('ISO 8601 - yy-mm-dd', "dateFormat", $(this).val()); });
</script>
答案 0 :(得分:1)
当内容页面呈现Textbox
id更改时。像这样使用Textbox
id
<script>
$(function () {
$("[id$=datepicker]").datepicker();
});
</script>
答案 1 :(得分:0)
使用输入字段尝试它,您的代码是正确的:
<input type="text" id="datepicker" runat="server" CssClass="txt-control" />
我不确定jquery是否可以使用“asp:TextBox”标签或将其替换?