js判断按钮a被点击加1分,按钮b被点击扣1分
展开全部
html代码:
<div class="box">你现在的分数:<span id="mymark"></span></div>
<input type="button" id="plus" value="a" />
<input type="button" id="reduce" value="b" />
js代码:
var abtn = document.getElementById("plus");
var bbtn = document.getElementById("reduce");
var mymark = 0;
var mark = document.getElementById("mymark");
abtn.onclick = function(){
if (mark.innerHTML != "") {
mymark++;
}
mark.innerHTML = mymark;
}
bbtn.onclick = function(){
if (mark.innerHTML != "") {
mymark--;
}
mark.innerHTML = mymark;
}
<div class="box">你现在的分数:<span id="mymark"></span></div>
<input type="button" id="plus" value="a" />
<input type="button" id="reduce" value="b" />
js代码:
var abtn = document.getElementById("plus");
var bbtn = document.getElementById("reduce");
var mymark = 0;
var mark = document.getElementById("mymark");
abtn.onclick = function(){
if (mark.innerHTML != "") {
mymark++;
}
mark.innerHTML = mymark;
}
bbtn.onclick = function(){
if (mark.innerHTML != "") {
mymark--;
}
mark.innerHTML = mymark;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询