如果您有一个JSF <h:commandLink>(使用a的onclick事件<a>来提交当前表单),那么在执行操作之前如何执行JavaScript(例如请求删除确认)?
<h:commandLink id="myCommandLink" action="#{myPageCode.doDelete}">
<h:outputText value="#{msgs.deleteText}" />
</h:commandLink>
<script type="text/javascript">
if (document.getElementById) {
var commandLink = document.getElementById('<c:out value="${myPageCode.myCommandLinkClientId}" />');
if (commandLink && commandLink.onclick) {
var commandLinkOnclick = commandLink.onclick;
commandLink.onclick = function() {
var result = confirm('Do you really want to <c:out value="${msgs.deleteText}" />?');
if (result) {
return commandLinkOnclick();
}
return false;
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
其他Javascript操作(如验证表单输入等)可以通过将调用替换为confirm()对另一个函数的调用来执行.
这对我有用:
<h:commandButton title="#{bundle.NewPatient}" action="#{identifController.prepareCreate}"
id="newibutton"
onclick="if(confirm('#{bundle.NewPatient}?'))return true; else return false;"
value="#{bundle.NewPatient}"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58891 次 |
| 最近记录: |