使用其他点击功能重新加载

Onclick reload with other onclick function

本文关键字:新加载 加载 功能 其他      更新时间:2023-09-26

有没有人知道是否可以在 1 个按钮中使用 2 次点击?我希望在按下按钮时获得重新加载页面。

这是原始按钮:

<a href="javascript:;" onclick="javascript:articleToCart('<z:esc mode="js" value=$z:value[article.number]>', document.getElementById('amount$z:iteration[article.current]').value)">

此致敬意弗兰克

编辑:

我的版本有效,但我找不到让return false工作的方法。这适用于IE和Firefox。

<center><input type="button" class="flowbutton" value="Kjøp" onclick="document.location.reload(true);javascript:articleToCart('<z:esc mode="js" value=$z:value[article.number]>',document.getElementById('amount$z:iteration[art‌​icle.current]').value)"> </center>

如果你调用一个函数,你已经这样做了,你可以在javascript中做任何你想做的事情。

<script type="text/javascript">
    function articleToCartMain() {
        articleToCart('<z:esc mode="js" value=$z:value[article.number]>', document.getElementById('amount$z:iteration[article.current]').value);
        //Put other function calls in here as well
        return false; //Prevents the page from reloading or scrolling to top
    }
</script>
<a href="#" onclick="return articleToCartMain();">Do something</a>

如果你想要这种类型的内联JS事件处理程序(在HTML源文件中),只需在要放在click事件上的两个语句之间使用逗号。

如果使用 JS 添加处理程序,请不要执行onclick = function() { //code of your second function };因为它会覆盖以前的处理程序。 在这种情况下,addEventListener/attachEvent 是"干净"的方式。

顺便说一句,关于伪网址(javascript:):

  • 在链接的 HREF 属性中,这通常被认为是不好的做法。如果这是一个按钮,看在上帝的份上,请使用<button>......所有 A 标签都应该在 href 属性中有一个真实的 URL。

  • 在点击中???无用的,无所畏惧地擦除它。