jQuery event.preventDefault() 在 h :commandLink 上不起作用

标签 jquery jsf richfaces spring-webflow

当用户单击取消链接时,我想将 jQuery 对话框显示为确认弹出窗口。 (“您真的要取消吗?”)

jQuery(#{rich:element('cancel')}).click(function(event) {
    var dialog = jQuery(#{rich:element('cancelDialog')});
    if (dialog.is(':visible')) {
        jQuery(#{rich:element('cancelDialog')}).dialog('close');
    }
    else {
        jQuery(#{rich:element('cancelDialog')}).dialog('open');
        event.preventDefault();
    }
});
<h:commandLink action="cancel" immediate="true" id="cancel" value="cancel" />

对话框正在打开,但事件不会被取消(--> 取消事件将继续)。当我使用 h:commandButton 时,它可以工作,但客户希望将其作为链接。

我使用 JSF 2.0 (MyFaces)、jQuery 1.6.1、Spring Webflow 2.3.0.RELEASE 和 JSF Framework Richfaces 4.0.0.FINAL。有谁知道这些框架的解决方案?我无法使用其他框架。

谢谢你, 帕特里克

最佳答案

在函数中使用return false而不是event.preventDefault()

要了解有关差异的更多信息:The difference between ‘return false;’ and ‘e.preventDefault();’

已编辑

由于还是不行,我建议使用onmousedown事件代替click,功能相同。 JSF h:commandLink and onclick events

关于jQuery event.preventDefault() 在 h :commandLink 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14137670/

相关文章:

javascript - JQuery Replacewith DIV 未加载

javascript - 在父 div 上使用 .height() 后,改变高度的子元素不再影响父元素的高度,为什么?

java - 如何发现Bean的变化

jsf - RichFaces 4 和 @ViewScoped

javascript - 在 Richfaces 4 中粘贴工具提示

c# - 将字典列表序列化为可接受的 DataTable Ajax 对象

javascript - 将函数中的对象分配给变量或调用setState而不使用这个?

java - 收到警告 : "There should only be one Seam phase listener per application" while starting native tomcat with exploded wars from IntelliJ

jsf - 为可重用 JSF 弹出窗口中的有条件禁用字段提交空值

java - 传递 SelectOneMenu 值以在 JSF/Primefaces 中添加功能