2013-05-13 118 views
0

我發現了一個可愛的jQuery彈出日曆。不過,我想使用用戶在存儲過程中選擇的日期。爲了保持這個例子簡單,我該如何拉/推這個日期來說標籤?從jQuery輸入框中提取數據

我試過把標籤放入函數中,但沒有喜悅。

的日期的節目在<input type="text" id="datepickerStart" />

但不...

<asp:Label ID="lbltest" runat="server" type="text" /> 

<meta charset="utf-8" /> 

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 
    <script> 
     $(function() { 
      $("#datepickerStart").datepicker({ 
       showOn: "button", 
       buttonImage: "images/calendar.gif", 
       buttonImageOnly: true 

      }); 
      $("#datepickerEnd").datepicker({ 
       showOn: "button", 
       buttonImage: "images/calendar.gif", 
       buttonImageOnly: true 

      }); 
     }); 




    </script> 
+1

什麼版本的asp是你的項目?一個asp標籤只是在html中創建一個跨度,你是不是想讓span的innerHtml包含datepicker中的文本? – Andrew 2013-05-13 13:26:02

+0

你需要標籤的'ClientID' - 'ID'只在服務器端,而不在客戶端。向我們展示呈現的HTML。 – Archer 2013-05-13 13:33:03

+0

asp.net 4,我遇到的問題是如何獲得中出現的值,因爲我想在其他地方使用此值。我可以將價值存儲在標籤中,或者如果有更好的方式,請告訴我。我沒有使用過jquery(禁止平常的淡入淡出的橫幅),但這看起來像是正確的道路。 – indofraiser 2013-05-13 13:36:48

回答

0

用於使用的另一種方法是聲明ID的名稱作爲在JavaScript變量,用於例如:

<script> 
     var lbltest = '<%= lbltest.ClientId %>'; 
     function setLabel (yourDate) 
     { 
      $("#" + lbltest).text(yourDate); 
     } 

     $(function() { 
      $("#datepickerStart").datepicker({ 
       showOn: "button", 
       buttonImage: "images/calendar.gif", 
       buttonImageOnly: true, 
       onSelect: setLabel 

      }); 
      $("#datepickerEnd").datepicker({ 
       showOn: "button", 
       buttonImage: "images/calendar.gif", 
       buttonImageOnly: true, 
       onSelect: setLabel  
      }); 
     }); 

</script> 

我假設您使用jQueryUI中的Datepicker構件

如您所見,「onSelect」屬性定義在用戶選擇日期時應調用哪個函數。

然後觸發標籤的更新。

+0

謝謝 - 我想我需要改變「yourDate」到其他東西? – indofraiser 2013-05-13 13:58:08

+0

嗨@indofraiser,是「yourDate」應該是從你的jQuery插件返回的任何變量 – KaraokeStu 2013-05-13 13:59:24

+0

所以我試着把datepickerStart放在那裏,它說它是未定義的。把 $(「#」+ lbltest).text(datepickerStart);在之內是對的地方嗎? – indofraiser 2013-05-13 14:01:53