简体   繁体   English

jQuery datepicker不会弹出?

[英]jquery datepicker not popping up?

i get these errors from IE7: 我从IE7得到这些错误:

Line 22: object doesnt support this property or method line 142: invalid argument 第22行:对象不支持此属性或方法。第142行:无效的参数

i am trying to do a datepicker on a textbox: 我试图在文本框上做一个日期选择器:

    <script>
        jQuery(function($) {
       $("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
    });

here's the textbox: 这是文本框:

<asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50"/>

here's the complete code: 这是完整的代码:

http://pastebin.com/Z08r6vMp http://pastebin.com/Z08r6vMp

the .mask worked fine before i added the datepicker , but neither work now. .mask在我添加datepicker之前工作正常,但现在都.mask工作。

what am i doing wrong? 我究竟做错了什么?

as TT. 作为TT。 suggested i changed it to this: 建议我将其更改为:

jQuery(function($) {
        //$("#occurrence_dateTextBox").mask("99/99/9999");
        //$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
        //$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
        $(".datepicker").datepicker(); 

    });

and

  <asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50" class="datepicker"/>

and still does not work 仍然不起作用

occurence_dateTextBox is the server ID of the control, you need the client side ID. occurence_dateTextBox是控件的服务器ID,您需要客户端ID。 You should also need to do the same for report_dateTextBox . 您还需要对report_dateTextBox进行相同的操作。 I'm not sure how that was working before. 我不确定以前的工作方式。

Try 尝试

$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();

Update 更新

Here is a simplified version of your page. 这是页面的简化版本。 Any code that is not necesary has been removed. 所有不需要的代码都已删除。

Notice that your old version includes multiple versions of jQuery, one from Googles CDN and another locally. 请注意,您的旧版本包括jQuery的多个版本,一个来自Google的CDN,另一个来自本地。 Now it pulls jQuery and the UI from the CDN. 现在,它从CDN中提取jQuery和UI。

You can copy and paste this into a new .aspx page and it will work. 您可以将其复制并粘贴到新的.aspx页中,它将起作用。

On your own version, I suggest using Firefox and Firebug and just looking at the console to get the exact error message, because it is coming from something else other than the following code. 在您自己的版本上,我建议使用Firefox和Firebug并仅查看控制台以获取确切的错误消息,因为它来自以下代码以外的其他内容。 You might not be pulling jQuery UI properly, or one of your other javascript calls is broken and it is causing problems with the datepicker. 您可能无法正确拉出jQuery UI,或者其他JavaScript调用之一中断了,并导致日期选择器出现问题。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" %>
<!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 id="Head1" runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript"></script>
    <script>

        jQuery(function($) {
            //$("#occurrence_dateTextBox").mask("99/99/9999");
            //$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
            $("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
            //$(".datepicker").datepicker(); 

        });

    </script>
</head>
<body><div id="container">
    <form id="form1" runat="server" class="niceform">

        <fieldset>

        <legend>Section A</legend>

        <dl>

            <dt><label for="occurrence_dateTextBox" class="datepicker">Occurrence Date:</label></dt>
            <dd><asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="report_dateTextBox">Report Date:</label></dt>
            <dd><asp:TextBox ID="report_dateTextBox" runat="server" size="50"/></dd>
        </dl>

        </fieldset>       

        <asp:Button ID="Button1" runat="server" Text="Button" />


    </form>
</div></body>
</html>

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

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