使用jquery在同一个按钮上调用不同的操作
我在 certHolderAddressChange 屏幕上有一个“保存”按钮,如下所示:
<p:commandButton id="cmdSave" value="#{label.Save}" action="save" update="certHolderAddressChange" />
在此屏幕中有一个复选框。要求是:当选中此复选框并单击“保存”按钮时,将打开一个弹出窗口。弹出窗口包含 2 个按钮:是和否。单击“是”按钮时,它会调用不同的操作。以下是弹出窗口代码:
<p:dialog header="#{label.primaryAdd}" widgetVar="dlg1" showEffect="bounce" hideEffect="explode" appendToBody="true">
<h:panelGrid columns="2">
<h:outputText value="#{label.msgPrimary}" />
<p:spacer width="30" height="10" />
<h:outputText />
<p:spacer width="30" height="10" />
</h:panelGrid>
<div align="center">
<p:commandButton immediate="true" value="#{label.yes}" action="makeAdd"/>
<p:spacer width="10" height="5" />
<p:commandButton value="#{label.no}" onclick="dlg1.hide()" type="button"/>
</div>
</p:dialog>
如果未选中复选框并单击“保存”按钮,则会调用一个简单的“保存”操作(不会打开弹出窗口)。为了实现这一点,我使用 jQuery 并根据复选框触发操作。这是 jQuery 代码:
<div>
<h:inputHidden value="#{certHolderDetail.primaryInd}" id="primaryID" />
</div>
<script>
jQuery("#cmdSave").click(function(e) {
var textvalue = jQuery('#primaryID').val();
if (textvalue == 'true') {
dlg1.show();
} else {
jQuery("#save").click();
}
});
</script>
它可以工作,但问题是在每种条件下都会调用 "save"
操作。但是如果我从按钮中删除 action="save"
,那么 else 部分就不起作用了。只有 if 条件适用于 jQuery 代码。
我想根据条件调用 "save"
和 "makeAdd"
操作。我怎样才能实现这个目标?
此外,在每种情况下(选中或未选中复选框),每次都会触发“保存”操作。我想在选中复选框时停止保存操作......
I have a Save button on certHolderAddressChange screen as below:
<p:commandButton id="cmdSave" value="#{label.Save}" action="save" update="certHolderAddressChange" />
In this screen there is one checkbox. The requirement is: when this checkbox is checked and the Save button is clicked, then one popup is opened. The popup contains 2 buttons: Yes and No. On click of the Yes button, it calls a different action. Here is the popup code:
<p:dialog header="#{label.primaryAdd}" widgetVar="dlg1" showEffect="bounce" hideEffect="explode" appendToBody="true">
<h:panelGrid columns="2">
<h:outputText value="#{label.msgPrimary}" />
<p:spacer width="30" height="10" />
<h:outputText />
<p:spacer width="30" height="10" />
</h:panelGrid>
<div align="center">
<p:commandButton immediate="true" value="#{label.yes}" action="makeAdd"/>
<p:spacer width="10" height="5" />
<p:commandButton value="#{label.no}" onclick="dlg1.hide()" type="button"/>
</div>
</p:dialog>
If checkbox is unchecked and Save button is clicked, a simple "save"
action is called (no popup is open). To achieve this, I am using jQuery and on the basis of the checkbox I am firing the action. Here is the jQuery code:
<div>
<h:inputHidden value="#{certHolderDetail.primaryInd}" id="primaryID" />
</div>
<script>
jQuery("#cmdSave").click(function(e) {
var textvalue = jQuery('#primaryID').val();
if (textvalue == 'true') {
dlg1.show();
} else {
jQuery("#save").click();
}
});
</script>
It's working but the problem is that on each condition the "save"
action is called. But is I remove the action="save"
from button, then the else part doesn't work. Only the if condition works in jQuery code.
I want to call "save"
and "makeAdd"
action on basis of the condition. How can I achieve this?
Also in each condition(checkbox checked or unchecked) "save" action is fired each time. i want to stop the save action when checkbox is checked.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您使用的是哪个版本的 jQuery
1.6+ 这就是您想要的
<1.6+ 这可以工作
Not sure which version of jQuery you are using
1.6+ this is what you want
<1.6+ this will work