在 <a></a> 中点击后刷新页面 [英] Refresh page after onclick in <a></a>

查看:57
本文介绍了在 <a></a> 中点击后刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<a onclick="removeCart('<?php echo $product['key']; ?>');" name="remove[<?php echo $product['key']; ?>]"  class="button"><span>Remove</span></a>

当我点击上面代码所示的Remove"按钮时,我希望onclick"被执行(执行),然后刷新页面.有什么想法吗?

When I click the "Remove" button, which is shown with the above code, I want the "onclick" to be executed (which is executed), and after that, the page to be refreshed. Any thoughts?

谢谢.

推荐答案

要使用 javascript 重新加载页面,您可以执行以下操作:

To reload the page using javascript you can do:

window.location.href=window.location.href

所以要在 onclick 后重新加载,只需将其添加到 onclick 的末尾,例如:

So to reload after the onclick simply add that to the end of onclick, eg:

onclick="removeCart('<?php echo $product['key']; ?>');window.location.href=window.location.href;"

带有延迟的完整代码

<a onclick="removeCart('<?php echo $product['key']; ?>');setTimeout('window.location.href=window.location.href', 100)" name="remove[<?php echo $product['key']; ?>]"  class="button"><span>Remove</span></a>

这篇关于在 &lt;a&gt;&lt;/a&gt; 中点击后刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆