jQuery UI确认对话框不返回true/false

编程入门 行业动态 更新时间:2024-10-08 04:32:31
本文介绍了jQuery UI确认对话框不返回true/false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有jQuery UI确认对话框:

I have jQuery UI confirm dialog:

function fnComfirm(title, content) { $("#dialog:ui-dialog").dialog("destroy"); $("#dialog-confirm p").html(content); $("#dialog-confirm").dialog({ title: title, resizable: false, height: 200, width: 486, modal: true, buttons: { "OK": function() { $( this ).dialog("close"); return true; }, Cancel: function() { $( this ).dialog("close"); return false; } } }); }

由JSF2 html调用:

Called by JSF2 html:

<a4j:commandButton action="#{userBean.makeSomething()}" type="button" onclick="if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}" />

但是我无法从该函数获得true/false值.我在此站点上看到了许多有关此问题的信息,并尝试了所有问题,但仍然没有成功.

But I can't get true/false value from this function. I saw many questions here on this site about it, tried all of them, but still get no success.

更新: <a4j:commandButton>的输出:

<input type="button" value="Make Something" onclick="jsf.util.chain(this,event,&quot;if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}&quot;,&quot;RichFaces.ajax(\&quot;frm:j_idt25\&quot;,event,{\&quot;incId\&quot;:\&quot;1\&quot;} )&quot;);return false;" name="frm:j_idt25" id="frm:j_idt25">

推荐答案

这是我使用的一种方法(您可以将示例的总体思路作为参考)

Here an approach that I use (You can take the general idea for your example)

您需要两个按钮

第一个将被隐藏,并通过在确认对话框中单击Yes进行调用,该隐藏按钮将成为将调用服务器端方法并执行以下操作的按钮render使用f:ajax

First one will be hidden and will be called as a result of clicking Yes in the confirm dialog, this hidden button will be the one that will call the server side method and will do the render using the f:ajax

<h:commandButton id="myHiddenButtonID" value="DeleteHiddenButton" action="#{userBean.makeSomething()}" style="display:none"> <f:ajax render="@form" ></f:ajax> </h:commandButton>

第二按钮将打开对话框,此按钮还将使用execute="@form"将表单提交到服务器(如果您在表中有选择列(选择表中的几列,然后单击按钮以显示).删除),例如您要在服务器Bean中更新的内容)

Second button will open the dialog, this button will also submit the form to the server with execute="@form" (in case you have selection column in table (select several columns in table and click button to delete) that you want to to update in the server bean for example)

<h:commandButton value="Delete"> <f:ajax execute="@form" onevent="openDialogFunc()"></f:ajax> </h:commandButton>

现在要执行js函数

function openDialogFunc(data){ if (data.status === 'success') { $('#dialog').dialog({ title: title, resizable: false, height: 200, width: 486, modal: true, buttons: { "Ok": function() { $("#myHiddenButtonID").click(); $(this).dialog("close"); }, "Cancel": function() { $(this).dialog("close"); } } }); } }

请注意,只有单击确定"对话框按钮,才会执行您的隐藏按钮$("#myHiddenButtonID").click();,否则将不会发生任何事情……

Notice that only upon clicking the OK dialog button there will be an execution of your hidden button $("#myHiddenButtonID").click(); otherwise nothing will happen...

从我过去回答过的类似问题中得到了答案如何使用JSF实现JQuery确认对话框

took this from similar question that I have answered in the past How to implement JQuery confirm dialog with JSF

更多推荐

jQuery UI确认对话框不返回true/false

本文发布于:2023-11-27 21:32:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639677.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   UI   jQuery   true   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!