亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用外部“ .js”文件

如何使用外部“ .js”文件

POPMUISE 2019-12-02 10:47:50
我有以下兩個javascript函數:1個showCountry()2showUser()我想將它們放在外部“ .js”文件中1個<a href="javascript:showCountry('countryCode')">countryCode</a>2<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>調用這些函數的正確語法是什么?
查看完整描述

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>

希望對您有幫助。...謝謝


查看完整回答
反對 回復 2019-12-02
?
Cats萌萌

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"; 

            }


查看完整回答
反對 回復 2019-12-02
?
拉風的咖菲貓

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


查看完整回答
反對 回復 2019-12-02
  • 3 回答
  • 0 關注
  • 642 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號