我想要一个<f:ajax>
组件将显示确认对话框,然后执行 action
标记如果 OK
如果 Cancel
则被选择或中止被选中。
我认为这会起作用,但事实并非如此(无论我在确认中选择什么,ajax 部分都会运行):
<f:ajax render="some_div">
<h:commandButton value="A Hazardous Button!"
onclick="show_confirm()" action="#{bean.doSomething}" />
</f:ajax>
-
function show_confirm()
{
var r=confirm("Are you sure you want to do this? This is totally hazardous!");
if (r==true)
{
return true;
}
else
{
return false;
}
}
知道为什么吗?
最佳答案
首先,您需要将 return
关键字添加到 onclick 处理程序中...尝试将 onclick="show_confirm()"
更改为 onclick="return show_confirm ()"
其次,您可以将函数简化为:
function show_confirm()
{
return confirm("Are you sure you want to do this? This is totally hazardous!");
}
关于javascript - 如果确认对话框为 "Cancel",则中止 Ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6402222/