我想仅在用户确认时执行一些脚本。
示例代码如下
if 'confirm' is clicked, then $confirm = true;
if($confirm)
{
some script
}
else
{
other script
}
?>
有两个按钮“确认”和“放弃”。如果单击确认,则 $confirm = true;
最佳答案
假设你有两个这样的按钮
<input type="button" name="confirm" id="confirm" value="confirm">
<input type="button" name="discard" id="discard" value="discard">
您可以使用 jquery 事件处理程序来获取单击了哪个按钮,如下所示
$(document).ready(function() {
$("#confirm").on('click',function(){
alert('Confirm clicked');
//If you need to communicate with the server the do an ajax call here
});
$("#discard").on('click',function(){
alert('Discard clicked');
//If you need to communicate with the server the do an ajax call here
});
});
您可以从 HERE 检查点击事件引用
关于javascript - 我想在单击按钮时生成 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701360/