本文介绍了如何在JSF< h:commandLink>之前执行Javascript?行动是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果你有一个JSF < h:commandLink>
(它使用 onclick
一个<$的事件c $ c>< a> 提交当前表单),如何在执行操作之前执行JavaScript(例如请求删除确认)?
If you have a JSF <h:commandLink>
(which uses the onclick
event of an <a>
to submit the current form), how do you execute JavaScript (such as asking for delete confirmation) prior to the action being performed?
推荐答案
<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>
其他Javascript操作(如验证表单输入等)可以通过将调用替换为<$ c来执行$ c> confirm()调用另一个函数。
Other Javascript actions (like validating form input etc) could be performed by replacing the call to confirm()
with a call to another function.
这篇关于如何在JSF< h:commandLink>之前执行Javascript?行动是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!