我有一些我試圖在HTML頁面上實現的javacript。代碼如下 - 如何在打開.html文件後立即運行它?它希望它在我打開它時立即提示我輸入重量。JavaScript:沒有在頁面上運行
<script type="text/javascript">
var weight = parseInt(prompt("What is your weight?"));
if (weight > 126) {
alert('Please enter a weight lighter than 126');
}
document.writeln('<br/>');
var wArray = ["fly", "superfly", "bantam", "superbantam", "feather"];
function recruit() {
if (0 < weight < 112){
document.writeln('You are in' + wArray[0] +'class!');
}
if (112 < weight < 115){
alert('You are in' + wArray[1] +'class!');
}
if (weight > 115 && weight < 118){
alert('You are in' + wArray[2] +'class!');
}
if(weight > 118 && weight < 122){
alert('You are in' + wArray[3] +'class!');
}
if (weight > 122&& weight < 126){
alert('Your weight class is' + wArray[4]);
}
</script>
只需要注意,你應該在''parseInt'中添加',10'。像這樣:'parseInt(提示(「你的體重是多少?」),10)'。 –