在继续之前显示 javascript 消息 [英] display a javascript message before proceeding
本文介绍了在继续之前显示 javascript 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,用于在用户按下按钮后获取数据库中的特定项目.如果找到该项目,我想通过 javascript 显示确认消息,但我不知道如何显示.
I have this code that is to fetch a particular item in the database after the user presses a button. If the item is found I would like to display a confirm message via javascript and I don't know how to show it.
从数据库中获取项目后
if(null!=mysqli_fetch_array($res)))
{
echo ""; // how can I call the javascript code here ?
}
和下面的确认框
<script type="text/javascript">
function onConfirm()
{
return confirm("Display this item ?");
}
</script>
推荐答案
使用jquery和ajax从数据库中获取值:
Use jquery and ajax to get the value from the database:
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
$.get("ajax.php", function(data){
if(data != "0"){
if(confirm("Display this item ?"))
{
//do something
}
}
});
ajax.php:
//other db code here
if(null!=mysqli_fetch_array($res)))
{
echo "1";
}
else{
echo "0";
}
这篇关于在继续之前显示 javascript 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文