我有一个加载可点击图像的主要功能(startGame),当你点击它时,它会消失(图像有自己的onClick功能可以工作)。这也是我的身体上传功能。
HTML:
<body onload="StartGame()"> //loads all the contents
此StartGame功能也是所有其他图像中的可点击div图像。单击此图像时,应重新加载整个页面,消失的图像应重新显示。
CSS:
div#startgame{ //clickable css image button
background-image: url(../graphics/startgame.png);
background-size: 165px 50px;
background-repeat: no-repeat;
width: 165px;
height: 50px;
如果我的功能同时是我的身体onload和刷新按钮,我每次点击它时如何刷新页面?
答案 0 :(得分:0)
您可以使用以下功能刷新页面
var reload = function(){
document.location = document.location;
}
因此,带按钮的HTML可能如下所示:
<button type="button" onclick="reload()">reload</button>
答案 1 :(得分:0)
您可以使用javascript方法reload
:
location.reload();
您需要在点击事件回调中使用它。
我希望有帮助:D
答案 2 :(得分:0)
$(document).ready(function(){
$("div#startgame").click(function(){
$('body').trigger('load');
});
});
你需要确保你有一个身体标签。或者为您想要的身体标签添加ID
答案 3 :(得分:0)
这样的事情:
$(document).ready(function(){
StartGame(); // You can start it from here too, removing the onload from body tag
// Intercept click event in your div, in this case by ID
$('#StartGame').click(function(){
StartGame(); // Call start game when it happens
});
});
&#13;
使用这样的代码,当您单击StartGame div时绑定StartGame()
的调用。
有了这个,你不需要重新加载页面。
答案 4 :(得分:0)
你可以用这个:
$( '#StartGame')。点击(函数(){
location.reload(); //每次点击
时重新加载页面
});