Refresh page after onclick in

2019-01-26 21:53发布

I have the following code:

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

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?

Thanks.

标签: refresh
3条回答
仙女界的扛把子
2楼-- · 2019-01-26 22:09

First answer is correct, also you could use

 window.location.reload();
查看更多
Luminary・发光体
3楼-- · 2019-01-26 22:21

To reload the page using javascript you can do:

window.location.href=window.location.href

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;"

edit: full code with delay

<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>
查看更多
祖国的老花朵
4楼-- · 2019-01-26 22:24

you can resubmit the page to itself by triggering the submit of an input field for instance. Assuming that your hyperlink got the id nextLink and you got an input with id submitMe you can do :


 $("#nextLink").click(function () {
//setting the url of the action target (your page or controller) $('#submitMe').attr('action', '/MySection/MyPage.php'); $("#submitMe").submit(); });

查看更多
登录 后发表回答