<html>
<head>
<title>JavaScript实验1</title>
<script type="text/javascript">
function fnScore(){
var score = document.getElementById("txtScore").value;
if( score>=60)
window.alert("及格");
else
window.alert("不及格");
}
</script>
</head>
<body>
<form name ="scoreForm">
请输入成绩:<input id ="txtScore" type="text"><br>
<input type="button" id="btn1" onclick="fnScore()" value="提交成绩">
<br>
</form>
</body>
</html>
就是引入外部js文件
新建一个score.js
把 function fnScore(){
var score = document.getElementById("txtScore").value;
if( score>=60)
window.alert("及格");
else
window.alert("不及格");
}
这个放到js中去,
在把这个html文件中的这段代码删掉就可以了