计时器倒计时 sql、asp.net c#、javascript
我有下一个 javascript 代码:
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "the auction end"
</script>
<script language="JavaScript" src="countdown.js"></script>
我的问题是...如何做到 TargetDate 从 sql 表中获取日期时间?我有一个带有设计的sql表:id,auctionEndTime ....我如何将其连接到目标日期?有可能吗?
i have the next javascript code:
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "the auction end"
</script>
<script language="JavaScript" src="countdown.js"></script>
my question is... how to do that the TargetDate will get the datetime from sql table? i have sql table with the desgin: id, auctionEndTime .... how i'm connect that to the targetdate? it is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Javascript
在客户端
运行,因此它无法直接访问数据库。但是,您可以从 javascript 调用服务,并且该服务可以以 JSON 格式或您的自定义格式从数据库获取记录。但是,如果您只需要在页面加载时获取一次值,那么您可以向页面添加一个隐藏字段,将隐藏字段值设置为您希望在服务器端设置的任何值,然后获取来自 javascript 的隐藏字段值并将其设置为TargetDate
。Javascript
runs atclientside
so it can't access the database directly. However, you could call a service from javascript and that service could fetch the record from the database in JSON format or may be in your custom format. However, If you need to fetch the value only once that is when page loads, so you could add ahidden
field to the page, sets the hidden field value to whatever value you like to at serverside, fetch the hidden field value from javascript and set it toTargetDate
.您可以在代码后面使用属性来直接填充 javascript。
ASP.Net页面:
页面代码隐藏:
You could use a property in code behind to fill up the javascript directly.
ASP.Net page:
Page code behind:
您可以在查询数据库后在
隐藏
字段中设置值,并从 Javascript 函数中的字段访问该值You can possibly set the value in a
hidden
field after querying the Database and access the value from the field in your Javascript function您还可以在代码隐藏中的适当位置使用 ClientScript 方法:
查看 此 MSDN 页面,了解有关通过 ClientScript 提供的方法的更多详细信息。
You could also use the ClientScript methods from the appropriate place in your code-behind:
Have a look at this MSDN page for more details on the methods availabe via ClientScript.