把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);
}
});
展开
 我来答
zhou2003737
2020-07-01 · TA获得超过1427个赞
知道小有建树答主
回答量:1082
采纳率:77%
帮助的人:402万
展开全部
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);
}
追问
$(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)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式