这是我最后一个问题的延续。 (谢谢你的答案)当达到最小/最大值时停止功能
即时通讯使用onclick增加和右键单击以减少'var b'这也导致'var max'增加/减少aswell但相反(增加'var b',减少'var最大值')
我有2个问题:
1)当‘变种b’升高到其最大的10随后‘变种最大值’被减少到40但即时通讯能够仍然减少‘变种最大’时点击'var b','var b'本身并不会增加。
2)可能与1相同,但当'var max'是低于其最大值50的任何数字时,当'var max'最小值为0'时,将'var b'或'var c'是增加'
所以我想我的问题是如何停止工作时,他们在最小/最大的功能,但仍然继续工作时改变。
我的功能:
var max=50;
function decrease(){
max = Math.max(max-1,0);
document.getElementById('boldstuff').innerHTML = max;
if(max < 1){
alert("There are no more skill points to be spent.");
}
}
function increase(){
max = Math.min(max+1,50);
document.getElementById('boldstuff').innerHTML = max;
}
var b=0;
function increase1(){
b = Math.min(b+1,10);
document.getElementById('boldstuff2').innerHTML = +b;
if(b > 9){
alert("You have spent all the points you can in this skill.");
}
}
function decrease1(){
b = Math.max(b-1,0);
document.getElementById('boldstuff2').innerHTML = +b;
}
var c=0;
function increase2(){
c = Math.min(c+1,10);
document.getElementById('boldstuff3').innerHTML = +c;
if(c > 9){
alert("You have spent all the points you can in this skill.");
}
}
function decrease2(){
c = Math.max(c-1,0);
document.getElementById('boldstuff3').innerHTML = +c;
}
我的按钮:
<div id='rem'>Remaining Skill Points: <b id="boldstuff">50</b></div>
<div id='skill1'><input type="submit" class="skillbutton" onclick="decrease();increase1();" oncontextmenu="increase();decrease1();return false;"></div>
<div id='counter1'><b id="boldstuff2">0</b></div>
<div id='skill2'><input type="submit" class="skillbutton" onclick="decrease();increase2();" oncontextmenu="increase();decrease2();return false;"></div>
<div id='counter2'><b id="boldstuff3">0</b></div>
我打算扩大我的答案了一下。给我几分钟。 – Pete
感谢您的惊人帮助:D – zhaobaloth
@zhaobaloth没有问题,这很有趣。你似乎对JavaScript非常陌生,我知道它可能会吓人和棘手(很大程度上是因为JavaScript太强大了,有100种方法可以做到“错误”,并且没有任何明显的惩罚)。我建议你检查了道格·克罗克福德的讲座上的JavaScript(谷歌他们),他们是惊人的,会做很多来告诉你为什么你应该做一些事情,不应该做别人。我感谢你对这门语言的兴趣,并且你的项目看起来很有趣。保持良好的工作,并保持它! – Pete