2013-11-14 42 views
0

即时通讯尝试从在线使用jquery生成我的datepicker。在我的标记,它是:跟着datepicker不工作jquery

<asp:TextBox ID="PStart" runat="server"></asp:TextBox> 

通过

<script type = "text/javascript"> 
    $(function() { 
     $("#PStart").datepicker({ 
      showOn: "button", 
      buttonImage: "images/calendar.gif", 
      buttonImageOnly: true 
     }); 
    }); 
</script> 

,并在我的我的网站主人的头我已经包括:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script type ="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script type ="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 

一点要注意的是,这个日期选择器嵌套在更新面板中,该面板仅在完成表单并单击提交/保存按钮后才更新。我将shildren设置为false并更新模式为有条件但没有显示,更不用于做出选择。

+0

它对我来说工作正常[DEMO](http://jsfiddle.net/7JJNu/) – abc123

+0

@ abc123自从他使用asp网络以来,不是一个有效的演示。 – Dom

+0

@Dom证明问题不在于javascript,jquery,jquery-ui ....这里的问题很可能是他的ID在页面呈现时不是'PStart' ......他需要检查使用broswer的元素......它可能都是从asp.net中弄坏的......这个问题有3种解决方案,但我需要他来验证它。 – abc123

回答

1

没有看到更多的代码,这是不可能的。但是,假设没有错误,则问题可能在于调用<asp:ContentPlaceHolder> & <asp:Content>

使用占位符时,asp控件将其ID更改为以下格式:{ContentPlaceHolderID}_ElementID

我建议之一:

  • 改变<asp:TextBox ID="PStart" runat="server"></asp:TextBox><input id="PStart" type="text"/>

  • 检查页面,找到该元素的实际ID(最有可能"#{ContentPlaceHolderID}_PStart")。

希望这有助于并让我知道如果您有任何问题!


的Site.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %> 
<!DOCTYPE html> 
<html lang="en"> 
<head runat="server"> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script type ="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script type ="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" /> 
</head> 
<body> 
    <form runat="server"> 
     <div id="body"> 
      <asp:ContentPlaceHolder runat="server" ID="MainContent" /> 
     </div> 
    </form> 
</body> 
</html> 

Default.aspx的:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> 
<asp:Content runat="server" ContentPlaceHolderID="HeadContent"> 
    <script type = "text/javascript"> 
     $(function() { 
      $("#MainContent_PStart, #PStart").datepicker({ 
       showOn: "button", 
       buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", 
       buttonImageOnly: true 
      }); 
     }); 
    </script> 
</asp:Content> 
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> 
    <asp:TextBox ID="PStart" runat="server"></asp:TextBox> 
    <input type="text" id="PStart"/> 
</asp:Content> 

结果:

enter image description here

+0

地狱呀!太感谢了!!! – New2This