3 回答

TA貢獻1824條經驗 獲得超8個贊
像這樣的代碼
<html>
<head>
<script type="text/javascript" src="path/to/script.js"></script>
<!--other script and also external css included over here-->
</head>
<body>
<form>
<select name="users" onChange="showUser(this.value)">
<option value="1">Tom</option>
<option value="2">Bob</option>
<option value="3">Joe</option>
</select>
</form>
</body>
</html>
希望對您有幫助。...謝謝

TA貢獻1805條經驗 獲得超9個贊
注意:-不要在外部JavaScript文件中使用腳本標簽。
<html>
<head>
</head>
<body>
<p id="cn"> Click on the button to change the light button</p>
<button type="button" onclick="changefont()">Click</button>
<script src="external.js"></script>
</body>
外部Java腳本文件:-
function changefont()
{
var x = document.getElementById("cn");
x.style.fontSize = "25px";
x.style.color = "red";
}

TA貢獻1995條經驗 獲得超2個贊
這是將外部javascript文件包含到HTML標記中的方法。
<script type="text/javascript" src="/js/external-javascript.js"></script>
external-javascript.js外部文件要包含在哪里。包含路徑和文件名時,請確保其正確。
<a href="javascript:showCountry('countryCode')">countryCode</a>
上面提到的方法對于錨標記是正確的,并且可以完美地工作。但是對于其他元素,您應該明確指定事件。
例:
<select name="users" onChange="showUser(this.value)">
謝謝,XmindZ
添加回答
舉報