2011-10-19 92 views
2
<script type="text/javascript"> 
     $(function() { 
     var newYear = new Date(); 
     newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 
     $('#countdown').countdown({ until: newYear, format: 'DHMS', layout: 
'<div id="timer">' + '<hr />'+ 
    '<div id="timer_days" class="timer_numbers">{dnn}</div>'+ 
    '<div id="timer_hours" class="timer_numbers">{hnn}</div>'+ 
    '<div id="timer_mins" class="timer_numbers">{mnn}</div>'+ 
    '<div id="timer_seconds" class="timer_numbers">{snn}</div>'+ 
'<div id="timer_labels">'+ 
    '<div id="timer_days_label" class="timer_labels">days</div>'+ 
    '<div id="timer_hours_label" class="timer_labels">hours</div>'+ 
    '<div id="timer_mins_label" class="timer_labels">mins</div>'+ 
    '<div id="timer_seconds_label" class="timer_labels">secs</div>'+ 
'</div>'+ 
'</div>' 
}); 
}); 
</script> 

我使用這個腳本來顯示我的網頁上的倒計時......但代替newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1);我想從我的數據庫中的新日期...我怎麼能去做??JavaScript的倒計時新的日期

ASPX代碼

<asp:HiddenField runat="server" ID="HF" /> 代碼後面[日期是10 \ 21 \ 2011] `

If defaultJob = False Then 
       sql.SelectCommand.CommandText = "SELECT OfferHeader, OfferDesc, MarketPrice, OfferPrice, Discount, PayInAdv, PayLater, ImageURL, AdTags,EndTime FROM " & offerTable & " WHERE CustID = '" & custID & "' AND BusiID=" & busiID & " AND OfferID=" & offerID 
      Else 
       sql.SelectCommand.CommandText = "SELECT OfferHeader, OfferDesc, MarketPrice, OfferPrice, Discount, PayInAdv, PayLater, ImageURL, AdTags,EndTime FROM " & offerTable & " WHERE CustID = '" & custID & "' AND BusiID=" & busiID & " AND OfferID=" & offerID 
      End If 

     Try 
      con.Open() 
      sql.Fill(table) 
      con.Close() 

      With table.Rows(0) 
       LblOfferHeader.Text = Convert.ToString(.Item(0)) 
       LblOfferDesc.Text = Convert.ToString(.Item(1)) 
       LblMarketPrice.Text = Convert.ToString(.Item(2)) 
       LblOfferPrice.Text = Convert.ToString(.Item(3)) 
       LblDiscount.Text = Convert.ToString(.Item(4)) 
       LblPayInAdv.Text = Convert.ToString(.Item(5)) 
       LblPayLater.Text = Convert.ToString(.Item(6)) 
       ImgOfferImage.ImageUrl = Convert.ToString(.Item(7)) 
       HF.Value = Convert.ToString(.Item(9)) 
      End With 
     Catch ex As Exception 
      'MsgBox(ex.Message) 
     Finally 
      sql.Dispose() 
      con.Close() 
      con.Dispose() 
     End Try` 

從數據庫來的日期是10 \ 21 \ 2011但定時器示出了36分鐘左....爲什麼?我究竟做錯了什麼???

回答

0

您可以在值的隱藏字段

$('[id$=hdf_Date]').val() // Get Date 

代碼存儲在頁面加載和使用JavaScript

HTML

<asp:HiddenField runat="server" ID="hdf_Date" /> 

抓住它的JavaScript背後

hdf_Date.Value = ValueFromDb; 
+0

我已經更新了問題,請看看。 –

1

現在修改y我們的標記有一個隱藏的元素

<input type="hidden" runat="server" id="hiddenDate" /> 

//僞代碼

Page_Load() 
{ 
    hiddenDate.value = datereadfromDatabase; 

} 

現在你的腳本可以是這樣的:

<script type="text/javascript"> 
     $(function() { 
     var newYear = $('#<%=hiddenDate.ClientID%>').val(); 
     $('#countdown').countdown({ until: newYear, format: 'DHMS', layout: 
'<div id="timer">' + '<hr />'+ 
    '<div id="timer_days" class="timer_numbers">{dnn}</div>'+ 
    '<div id="timer_hours" class="timer_numbers">{hnn}</div>'+ 
    '<div id="timer_mins" class="timer_numbers">{mnn}</div>'+ 
    '<div id="timer_seconds" class="timer_numbers">{snn}</div>'+ 
'<div id="timer_labels">'+ 
    '<div id="timer_days_label" class="timer_labels">days</div>'+ 
    '<div id="timer_hours_label" class="timer_labels">hours</div>'+ 
    '<div id="timer_mins_label" class="timer_labels">mins</div>'+ 
    '<div id="timer_seconds_label" class="timer_labels">secs</div>'+ 
'</div>'+ 
'</div>' 
}); 
}); 
</script> 
+0

我已更新問題請看看。 –