把jQuery代码改为js代码,代码如下?
<scriptsrc="jquery-3.5.0.js"></script><scriptlanguage=javascript>$(function(){game_st...
<script src="jquery-3.5.0.js"></script>
<script language=javascript>
$(function(){
game_start=false;
var game_life=0;
var game_score=0;
var loop_state;
var div_down;
$("#flag").click(function()
{
if(game_start==true)
{
game_over();
}
else
{
game_start=true;
game_life=3;
game_score=0;
$("#show_life").html("生命数:"+game_life);
$("#show_score").html("得分数:"+game_score);
create_ingot();
loop_state=setInterval(function(){create_ingot()},1500);
div_down=setInterval(function(){go_down()},50);
}
}); 展开
<script language=javascript>
$(function(){
game_start=false;
var game_life=0;
var game_score=0;
var loop_state;
var div_down;
$("#flag").click(function()
{
if(game_start==true)
{
game_over();
}
else
{
game_start=true;
game_life=3;
game_score=0;
$("#show_life").html("生命数:"+game_life);
$("#show_score").html("得分数:"+game_score);
create_ingot();
loop_state=setInterval(function(){create_ingot()},1500);
div_down=setInterval(function(){go_down()},50);
}
}); 展开
展开全部
onload = function(){
game_start=false;
var game_life=0;
var game_score=0;
var loop_state;
var div_down;
document.querySelector("#flag").onclick(function()
{
if(game_start==true)
{
game_over();
}
else
{
game_start=true;
game_life=3;
game_score=0;
document.querySelector("#show_life").innerHTML = "生命数:"+game_life;
document.querySelector("#show_score").innerHTML="得分数:"+game_score;
create_ingot();
loop_state=setInterval(function(){create_ingot()},1500);
div_down=setInterval(function(){go_down()},50);
}
game_start=false;
var game_life=0;
var game_score=0;
var loop_state;
var div_down;
document.querySelector("#flag").onclick(function()
{
if(game_start==true)
{
game_over();
}
else
{
game_start=true;
game_life=3;
game_score=0;
document.querySelector("#show_life").innerHTML = "生命数:"+game_life;
document.querySelector("#show_score").innerHTML="得分数:"+game_score;
create_ingot();
loop_state=setInterval(function(){create_ingot()},1500);
div_down=setInterval(function(){go_down()},50);
}
追问
$(function(){变成onload = function(){这里如果不采用onload而是Document.DOMContentLoaded事件来替换的话应该怎么做
追答
function handler(){
game_start=false;
var game_life=0;
var game_score=0;
var loop_state;
var div_down;
document.querySelector("#flag").onclick(function()
{
if(game_start==true)
{
game_over();
}
else
{
game_start=true;
game_life=3;
game_score=0;
document.querySelector("#show_life").innerHTML = "生命数:"+game_life;
document.querySelector("#show_score").innerHTML="得分数:"+game_score;
create_ingot();
loop_state=setInterval(function(){create_ingot()},1500);
div_down=setInterval(function(){go_down()},50);
}
document.addEventListener('DOMContentLoaded',handler)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询