0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <link type="text/css" href="App_Themes/jquery-ui-1.7.3.custom.css" rel="stylesheet" />
        <script src="Scripts/jquery-1.3.2.min.js"type="text/javascript"></script>
        <script src="Scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>

    <script type="text/javascript" >
       $("#myButton").click(function() {
          $("#datepicker").datepicker("show");
       });
    </script>
    <form id="form1" runat="server">
    <div>
    <table border="1px" >
     <tr>
        <td><asp:Label ID="Label4" runat="server" Text="Text"></asp:Label></td>
        <td><asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td>
    </tr>

    <tr>
        <td><asp:Label ID="Label1" runat="server" Text="Date"></asp:Label></td>
        <td><asp:TextBox ID="datepicker" runat="server"></asp:TextBox>
            <input id="myButton" type="button" value="button" />
        </td>
    </tr></table> 
    </div>
    </form>
</body>
</html>

这是我的网络表单设计代码..

侧脚本标签中写入的单击功能 wat 不起作用...!哪里不对了。??

4

5 回答 5

3

.datepicker( "show" )-->>Call up a previously attached date picker.但我看不到你在哪里初始化你的日期选择器..先这样称呼它......$("#datepicker").datepicker();

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

    $("#myButton").click(function() {
       $("#datepicker").datepicker("show");
    });
});

尝试$("#datepicker").datepicker();在演示中取消注释此行 ()

演示

于 2010-07-12T08:01:39.623 回答
2

将您的脚本添加到document.ready(...)函数中。

它不工作的一个原因是当你的脚本被执行时,该myButton元素还没有被添加到 DOM 中,因此找不到。使用 jquery 时,通常应将 javascript 代码包装在 中,$(document).ready(..)以确保在调用代码时 DOM 已完全加载。尝试以下操作:

<script type="text/javascript" >
  $(document).ready(function(){
      $("#myButton").click(function() {
          $("#datepicker").datepicker("show");
      });
  });
</script>
于 2010-07-12T07:59:33.020 回答
1

从文档中:

节目

签名:.datepicker("show")

调用以前附加的日期选择器。

所以首先你需要附上它!例如:

$(document).ready(function() {
    var textBox = $('#<%= this.datepicker.ClientID %>');
    var icon = $('#myButton');
    var datepicker = textBox.datepicker();
    icon.click(function() {
        datepicker.datepicker('show');
    });
});

您可能会使用图标触发器

于 2010-07-12T08:00:04.953 回答
0

查看已生成的源代码。id 还叫myButtonanddatepicker吗?除非另有说明并且您使用的是版本 4,否则 id 通常由 asp.net 重写。

于 2010-07-12T07:52:11.423 回答
-1

您将需要使用控件的客户端 ID,例如

$("#<%=datepicker.ClientId%>").datepicker("show");

于 2010-07-12T07:59:12.057 回答