当用户点击“确定”时运行另一个JavaScript。在alertbox上 [英] Run another javascript when user clicks "ok" on alertbox

查看:138
本文介绍了当用户点击“确定”时运行另一个JavaScript。在alertbox上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个脚本,每10秒钟检查一次数据库,如果数据已经用javascript alert框改变,notifys用户。但是我需要在用户看到警报并且点击确定时更改数据库。那么,当用户在javascript alert上单击确定时,可以运行javascript函数吗?

因此,例如

 < html> 
< head>
< script type =text / javascript>
函数show_alert()
{
alert(New data!);
}
< / script>
< / head>
< body>

< input type =buttononclick =show_alert()value =显示警告框/>

< / body>
< / html>

当用户点击确定时,它应该运行此功能

 函数UpdateDB()
{
jQuery.ajax({
类型:POST,
url:update。 php,
data:'condition = ok',
cache:false,

});


解决方案 alert 函数暂停执行代码,直到它被解散。这意味着您可以在调用 alert 方法之后简单地放置您想要在警报点击后运行的任何代码。

  alert(New data!); 
UpdateDB();


Basically I have a script that checks database every 10 seconds and notifys user if data has changed with a javascript alert box. But I need the database also to be changed when user has seen the alert and clicked OK. So is it possible to make a javascript function run when user clicks "OK" on javascript alert?

So for example

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("New data!");
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" />

</body>
</html>

And when user clicks OK it should run this function

  function UpdateDB()
  {
      jQuery.ajax({
       type: "POST",
       url: "update.php",
       data: 'condition=ok',
       cache: false,

     });
 }

解决方案

The alert function halts execution of the code until it's dismissed. This means that any code you want to run after the alert has been clickd can simply be placed after the call to the alert method.

alert("New data!");
UpdateDB();

这篇关于当用户点击“确定”时运行另一个JavaScript。在alertbox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆