jquery日期选择器不使用母版页

时间:2016-02-03 07:05:37

标签: javascript jquery asp.net master-pages jquery-ui-datepicker

jQuery datepicker无法使用母版页。添加母版页ID时datepicker无效。

请查看以下代码以获取更多信息。

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
   <title>jQuery UI Datepicker - Default functionality</title>
   <link rel="stylesheet" ref="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
   <script src="//code.jquery.com/jquery-1.10.2.js"></script>
   <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
   <link rel="stylesheet" href="/resources/demos/style.css">
   <script>
      $(function () {
         $("#datepicker").datepicker();
      });
   </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   <p>Date: <input type="text" id="datepicker"></p>
</asp:Content>

1 个答案:

答案 0 :(得分:1)

您需要添加一个属性ClientIDMode="Static",以便按原样保存id

我建议改为使用class,但不要覆盖服务器生成的ID。

像:

<input type="text" id="datepicker" class="datepicker" />

然后:

$(function () {
   $(".datepicker").datepicker();
});