因此,我尝试创建一个东西,您单击一个按钮,它会将上面的数字加1。
我的HTML代码:
<center><span id="timesClicked">0</span></center>
<button type="button" class="btn btn-default" onclick="btnClick()">Click</button>
我的JS代码:
var mdb = {
"widgets": {
"amount":0
"stats": {
"timesClicked":0,
}
}
function btnClick(n){
mdb.widgets.amount += n;
mdb.stats.timesClicked += n;
return true
}
我真的不知道如何将数字链接到JS对象,有人可以帮助我吗?
对于您来说,这可能过于简化了……我不确定该对象的用途是什么。基本上,您需要使用它来更新HTML中的timesClicked数字:
document.getElementById("timesClicked").innerHTML = timesClicked;
我已经去除了一些目标代码,因此使用起来更容易。这是我正在使用的javascript:
Java脚本
var timesClicked = 0;
function btnClick(){
timesClicked ++;
document.getElementById("timesClicked").innerHTML = timesClicked;
return true
}
德莫斯
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句