admin管理员组文章数量:1302981
Here is the Bin. I am trying to make an example of reloading the page by using location.reload()
in the function refresh()
and using onclick='refresh()'
in a button. For some reason the page is not reloading.
The JS function:
function refresh() {
location.reload();
}
The HTML button:
<button onclick='refresh()'>Try Refreshing!</button>
Here is the Bin. I am trying to make an example of reloading the page by using location.reload()
in the function refresh()
and using onclick='refresh()'
in a button. For some reason the page is not reloading.
The JS function:
function refresh() {
location.reload();
}
The HTML button:
<button onclick='refresh()'>Try Refreshing!</button>
Share
asked Sep 1, 2013 at 15:19
Joe PigottJoe Pigott
8,4697 gold badges33 silver badges43 bronze badges
1
- You cannot access the function. Its out of scope. – CharliePrynn Commented Sep 1, 2013 at 15:22
4 Answers
Reset to default 5Your refresh method is not in the global scope - it's enclosed within your document.ready.
Move it out from document.ready into it's own script tag.
<script>
function refresh() {
location.reload();
}
</script>
The edited bin
The refresh()
function isn't in the global scope. In order to make the function globally accessible, you can do this:
window.refresh = function() {
location.reload();
};
Your function is defined inside the
$(document).ready(function () {
...
});
body, so the scope of the function name is just that body. As a result, you can't reference it from inline onXXX
attributes.
Either associate it with the element using
$("#buttonid").click(refresh);
or define the function outside the document ready function.
you can do directly as
<button onclick="window.location.reload()">Try refreshing!</button>
本文标签: htmlSimple javascript reload not workingStack Overflow
版权声明:本文标题:html - Simple javascript reload not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741670168a2391554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论