我有一个Flash游戏网站。当我进入游戏时,我有一个标有" Play Game"的按钮。用户需要按下此按钮才能开始游戏。但我不希望用户必须使用按钮启动游戏。如何以及我可以改变什么?这是来自my website的javascript。
}
function sgame() {
var x=document.getElementById('gamefirst').style;
var y=document.getElementById('gamesecond').style;
if(x.display=='block') { x.display='none'; y.display='block'; }
else { x.display='block'; y.display='none'; }
}
也许
function swf(src, width, height) {
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="733" height="550" id="currentGame">');
document.write('<param name="movie" value="' + src + '">');
document.write('<param name="quality" value="high">');
document.write('<embed src="' + src + '" id="currentEmbedGame" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="733" height="550" menu="0"></embed>');
document.write('</object>');
答案 0 :(得分:2)
<script type="text/javascript">
window.onload = function(event) {
// your code here
};
// equivalent with jQuery (when window loads)
jQuery(window).load(function(event) {
// your code here
});
// alternatively with jQuery (when DOM is ready)
jQuery(document).ready(function(event) {
// your code here
});
// you can also call a function if this <script>-block is reached (loaded) first time
// place the <script>-block before body-tag is closing and you have nearly what DOM-ready does.
someFunction();
</script>
有关window load
和dom ready
之间的差异,请参阅此处:window.onload vs $(document).ready()
简而言之:在dom准备就绪之后,window.onload会出现。所有图像都已加载。
答案 1 :(得分:1)
在您的HTML中,您可以尝试:
<body onload="startgame();">
或者在您的JS文件中,您可以尝试:
window.onload=function(){//whatever you need to do;}
答案 2 :(得分:1)
在你的身体加载后加载一个函数,如下所示:
<body onload="startgame();">
然后创建函数
function startgame() {
alert('Body has loaded!');
}
答案 3 :(得分:0)
加载功能怎么样?
Jquery:JQuery(document).ready(你的函数在这里)
JavaScript:window.onload =这里的功能