简体   繁体   English

如何使用jQuery在asp.net中实现datepicker?

[英]how to implement datepicker in asp.net using jquery?

    <script src="<%=("../Scripts/jquery-1.6.1.min.js") %>" type="text/javascript" />
   <script src="<%=("../Scripts/jquery-datePicker.js") %>" type="text/javascript" />

<script type="text/javascript">

    $(function() {

     $("#txtDate").datepicker();       

    });   

   </script>

I have used this code but it doesnot show me the popup calender on click on textbox. 我使用了此代码,但单击文本框后未显示弹出日历。 what can be the problem. 可能是什么问题。 it doesnot give any error. 它不会给出任何错误。

Perhaps you should use the document.ready function 也许您应该使用document.ready函数

$(document).ready(function() {
 $("#txtDate").datepicker();       
});

ID of ASP.NET server control is different than that of the normal HTML ID. ASP.NET服务器控件的ID与普通HTML ID的ID不同。 So if you are using a Server control, then run your code, open the page source, get the ID that is displayed in the page source and use this ID instead of txtDate. 因此,如果使用服务器控件,则运行代码,打开页面源,获取页面源中显示的ID,然后使用此ID代替txtDate。

Also use 也使用

$(document).ready(function() { $("#<id>").datepicker(); });

why not set path directly? 为什么不直接设置路径? and close script tag with this </script> 并使用</script>关闭脚本标签

<script src="../Scripts/jquery-1.6.1.min.js" type="text/javascript" ></script>
<script src="../Scripts/jquery-datePicker.js" type="text/javascript" ></script>

Use ClientID for server control 使用ClientID进行服务器控制

<script type="text/javascript">

    $(function() {

     $("#<%= txtDate.ClientID %>").datepicker();       

    });   

   </script>

you can also use ready function 您也可以使用就绪功能

<script type="text/javascript">
$(document).ready(function() {
 $("#<%= txtDate.ClientID %>").datepicker();       
});
</script>

if ID selector doesn't work then use class selector it is good for ASP.NET server control 如果ID选择器不起作用,则使用类选择器,这对ASP.NET服务器控件是有利的

<asp:TextBox ruat="server" ID="txtDate" CssClass="DateField"></asp:TextBox>

<script type="text/javascript">
    $(document).ready(function() {
     $(".DateField").datepicker();       
    });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM