Skip to main content
 首页 » 编程设计

jquery 日期选择器无法在 ASP.NET Web 表单中工作

2026年07月28日8dudu

以下日期选择器在 ASP.NET Web 表单中不起作用。我更改了代码很多次,甚至其他示例都无法工作,甚至创建新页面来测试仍然无法工作。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type = "text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type = "text/javascript"></script> 
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel = "Stylesheet" type="text/css" />  
    <script type="text/javascript"> 
 
//Code Starts 
$(document).ready(function() { 
 
     $('#Text1').datepicker(); 
      $('#<%=txtBookDate.ClientID %>').datepicker(); 
});​ 
 
</script> 
</head> 
 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:TextBox ID="txtBookDate" runat="server"></asp:TextBox><input id="Text1" type="text" /> 
    </div> 
    </form> 
</body> 
</html> 

jsFiddler 上的示例正在运行

http://jsfiddle.net/ANdUK/3/

请您参考如下方法:

问题可能是 id 以某种方式发生了更改,因为它们位于表单内。您应该检查生成的 id 并使用它。顺便说一句,如果没有 jQuery UI,jsfiddle 上的示例将无法工作

编辑尽量不要在脚本标记中放置空格,并尝试在表单之外进行正常输入

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>