繁体   English   中英

为什么确认后我的 onclick 事件中的代码没有运行?

[英]Why does the code in my onclick event after a confirm not run?

考虑以下代码:

<a href="#" onclick="return confirm(&quot;sure to remove?&quot;);;

new Ajax.Updater('12', '/admin/files/remove/id/12', {asynchronous:true, evalScripts:false});; 

return false;">Remove

</a>

它不起作用,我不知道为什么。

我该如何解决这个问题?

return语句之后没有执行任何操作。 当你回来时,你回来了。 这就是return所在。 因此没有代码后return confirm(&quot;sure to remove?&quot;); 将永远运行。

你可能想要这样的东西:

<a href="#" onclick="
    if (confirm(&quot;sure to remove?&quot;)) {
        new Ajax.Updater('12', '/admin/files/remove/id/12', {asynchronous:true, evalScripts:false});
    }
    return false;">Remove</a>

尽管创建一个适当的函数并调用它会好得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM