我想我还差得远,但是我正在尝试创建一个场景,单击ID 12a,我想提醒用户输入数字并继续输入数字,直到他们用完5个箭头。我哪里做错了?
var arrows = 5;
alert('You have ' + arrows + ' arrows!');
var shot = prompt('How many arrows would you like to shoot?', '1');
var shotten = parseInt(shot);
$('#12a').click(function(){
if(isNaN(shotten)){
alert('You must enter a valid number of arrows!');
} else if(shotten > arrows){
alert('Sorry, but there are only ' + arrows + ' arrows. You can not shoot ' + shotten + ' arrows!');
} else if(shotten < 0){
alert('Sorry, but you cannot shoot less than 0 arrows!');
} else {
arrows -= shotten;
alert('Now there are only ' + arrows + ' arrows!');
}
});
<p>There's a half-elf running at you. You can shoot him with your arrows if you'd like. </p>
<p>
<input type="submit" name="12a" id="12a" value="Let's do it.">
</p>
开发人员在使用JavaScript /网页时应注意的几件事。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句