<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);
我怎么能这样做?
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 :(得分:1)
现在修改您的标记以获得隐藏元素
<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>
答案 1 :(得分:0)
您可以在页面加载时将值存储在隐藏字段中并使用javascript
抓取它HTML
<asp:HiddenField runat="server" ID="hdf_Date" />
的Javascript
$('[id$=hdf_Date]').val() // Get Date
背后的代码
hdf_Date.Value = ValueFromDb;