计时器倒计时 sql、asp.net c#、javascript

发布于 2024-11-07 12:26:42 字数 548 浏览 0 评论 0原文

我有下一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木緿 2024-11-14 12:26:42

Javascript客户端运行,因此它无法直接访问数据库。但是,您可以从 javascript 调用服务,并且该服务可以以 JSON 格式或您的自定义格式从数据库获取记录。但是,如果您只需要在页面加载时获取一次值,那么您可以向页面添加一个隐藏字段,将隐藏字段值设置为您希望在服务器端设置的任何值,然后获取来自 javascript 的隐藏字段值并将其设置为 TargetDate

Javascript runs at clientside 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 a hidden 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 to TargetDate.

七七 2024-11-14 12:26:42

您可以在代码后面使用属性来直接填充 javascript。

ASP.Net页面:

<script language="JavaScript">
  TargetDate = "<% = TargetDate %>"; /*this is a property in code behind*/
  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>

页面代码隐藏:

public string TargetDate{
  // Build code to get date from database
  string sql = "SELECT targetDate from Events where Event_ID = 1309";
  // execute sql
  // ...
  return dbvalue;
}

You could use a property in code behind to fill up the javascript directly.

ASP.Net page:

<script language="JavaScript">
  TargetDate = "<% = TargetDate %>"; /*this is a property in code behind*/
  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>

Page code behind:

public string TargetDate{
  // Build code to get date from database
  string sql = "SELECT targetDate from Events where Event_ID = 1309";
  // execute sql
  // ...
  return dbvalue;
}
无声静候 2024-11-14 12:26:42

您可以在查询数据库后在隐藏字段中设置值,并从 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

秋风の叶未落 2024-11-14 12:26:42

您还可以在代码隐藏中的适当位置使用 ClientScript 方法:

ClientScript.RegisterClientScriptBlock(this.GetType(), 
                                       "AuctionTargetDateScript", 
                                       string.Format("TargetDate = '{0}';", TargetDateFromDB), 
                                       true);

查看 此 MSDN 页面,了解有关通过 ClientScript 提供的方法的更多详细信息。

You could also use the ClientScript methods from the appropriate place in your code-behind:

ClientScript.RegisterClientScriptBlock(this.GetType(), 
                                       "AuctionTargetDateScript", 
                                       string.Format("TargetDate = '{0}';", TargetDateFromDB), 
                                       true);

Have a look at this MSDN page for more details on the methods availabe via ClientScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文