问题
I need a button that will refresh the page on the user's click. I tried this:
<input type="button" value="Reload Page" onClick="reload">
or
<input type="button" value="Refresh Page" onClick="refresh">
But neither worked.
回答1:
Use onClick
with window.location.reload()
, i.e. :
<button onClick="window.location.reload();">Refresh Page</button>
Or history.go(0)
, i.e.:
<button onClick="history.go(0);">Refresh Page</button>
Or window.location.href=window.location.href
for 'full' reload, i.e.:
<button onClick="window.location.href=window.location.href">Refresh Page</button>
The Button element - developer.mozilla.org
回答2:
This works for me
HTML
<button type="submit" onClick="refreshPage()">Refresh Button</button>
JavaScript
<script>
function refreshPage(){
window.location.reload();
}
</script>
回答3:
<a onClick="window.location.reload()">Refresh</a>
This really works perfect for me.
回答4:
Only this realy reloads page (Today)
<input type="button" value="Refresh Page" onClick="location.href=location.href">
Others do not exactly reload. They keep values inside text boxes.
回答5:
button that refresh the page on click
Use onClick button with window.location.reload():
<button onClick="window.location.reload();">
回答6:
<button onclick=location=URL>Refresh</button>
This might look funny but it really does the trick.
回答7:
just create the empty reference on link such as following
<a href="" onclick="dummy(0);return false;" >
回答8:
If you are looking for a form reset:
<input type="reset" value="Reset Form Values"/>
or to reset other aspects of the form not handled by the browser
<input type="reset" onclick="doFormReset();" value="Reset Form Values"/>
Using jQuery
function doFormReset(){
$(".invalid").removeClass("invalid");
}
回答9:
Use this its work fine for me to reload the same page:
<button onClick="window.location.reload();">
回答10:
window.opener.location.href ='workItem.adm?wiId='+${param.wiId};
It will go to the required path and you won't get any resend prompt.
来源:https://stackoverflow.com/questions/29884654/button-that-refreshes-the-page-on-click