第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

需要幫助在外部 js 文件中定義我的變量

需要幫助在外部 js 文件中定義我的變量

慕田峪7331174 2022-10-27 10:45:03
我正在為我的一個(gè)班級(jí)項(xiàng)目做一個(gè)網(wǎng)站,它沒(méi)什么特別的,但我無(wú)法定義我的變量,也不知道如何定義,因?yàn)槲覍?duì)此比較陌生,我一直在嘗試使用不同的方式來(lái)調(diào)用變量,但他們不會(huì)定義,我不知道為什么我一直在使用括號(hào),所以任何幫助將不勝感激/*variables used in index.html document*/var square = document.getElementById("square")var clickMe = document.getElementById('clickMe');/*What the button is suppose to do*/function doDemo() {      var button = this;    square.style.backgroundColor = "#ff4545";    button.setAttribute("diabled", "true");    setTimeout(clearDemo, 2000, button);}/*removes the attributes when you click the button again*/function clearDemo (button) {    var square = document.getElementById("square");    square.style.backgroundColor = "transparent";    button.removeAttribute("diabled");}clickMe.onclick = doDemo;/* color for webpage*/html{    background: silver;    }/* setting for heading 1 */h1{    color: saddlebrown;    font-family: Helvetica, sans-serif;    text-align: center;    font-size: 55px;}/* settings for heading 2 */h2{    font-size: 30px;    color: #D2691E;    font-family: Helvetica, sans-serif;}/* settings for the introduction line */.intro{    text-align: center;    padding-bottom: 1em;    font-family: arial;    margin: auto;    max-width: 1100px;    line-height: 2;    font-size: 20px;       }/* settings for images */.shake {   display:block;margin-left: auto;    margin-right: auto;    width: 30%;}/* settings for body structure */.prime{    padding-bottom: 1em;    font-family: arial;    margin-right: auto;    max-width: 900px}#square{    width: 100px;    height: 100px;    border: 2px inset gray;    margin-bottom: 1em;}button{    padding: .5em 2em;}
查看完整描述

3 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

現(xiàn)代瀏覽器中最有效的方法是defer在你的腳本標(biāo)簽中使用屬性標(biāo)記頭部的標(biāo)記,這樣你就可以將頭部中的單行代碼更改為:

<script defer type="text/javascript" src="script.js"></script>

基本上這是最好的方法,因?yàn)榻馕鼍拖裎覀儗⒛_本放在 body 標(biāo)記的末尾一樣完成,但總體而言,腳本執(zhí)行之前完成得很好,因?yàn)槟_本已與 HTML 解析并行下載。Usingdefer給你兩全其美:異步加載,但它會(huì)等到 DOM 準(zhǔn)備好。

有一篇非常好的文章詳細(xì)解釋了每種 javascript 加載技術(shù)的效率。在這里。


查看完整回答
反對(duì) 回復(fù) 2022-10-27
?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

建議使用 eventListeners ,這將解決問(wèn)題


此外,您需要確保正確拼寫 - 它是disabled


/*variables used in index.html document*/

let square; 

let clickMe;


/*What the button is suppose to do*/

function doDemo() {

  square.style.backgroundColor = "#ff4545";

  clickMe.setAttribute("disabled", "true");

  setTimeout(clearDemo, 2000);

}

/*removes the attributes when you click the button again*/

function clearDemo(button) {

  square.style.backgroundColor = "transparent";

  clickMe.removeAttribute("disabled");

}


window.addEventListener("load", function() {

  square = document.getElementById("square")

  clickMe = document.getElementById('clickMe');

  clickMe.addEventListener("click", doDemo);

});

/* color for webpage*/


html {

  background: silver;

}



/* setting for heading 1 */


h1 {

  color: saddlebrown;

  font-family: Helvetica, sans-serif;

  text-align: center;

  font-size: 55px;

}



/* settings for heading 2 */


h2 {

  font-size: 30px;

  color: #D2691E;

  font-family: Helvetica, sans-serif;

}



/* settings for the introduction line */


.intro {

  text-align: center;

  padding-bottom: 1em;

  font-family: arial;

  margin: auto;

  max-width: 1100px;

  line-height: 2;

  font-size: 20px;

}



/* settings for images */


.shake {

  display: block;

  margin-left: auto;

  margin-right: auto;

  width: 30%;

}



/* settings for body structure */


.prime {

  padding-bottom: 1em;

  font-family: arial;

  margin-right: auto;

  max-width: 900px

}


#square {

  width: 100px;

  height: 100px;

  border: 2px inset gray;

  margin-bottom: 1em;

}


button {

  padding: .5em 2em;

}

<!DOCTYPE html>

<!-- will need to make java, and css files and link them-->

<html>

<!--website title and attributes-->


<head>

  <title>Milkshakes</title>

  <meta charset="UTF-8">

  <link rel="stylesheet" href="main.css">

  <script type="text/javascript" src="script.js"></script>

</head>

<!-- make seprate class for each elment here-->


<body>

  <h1>Milkshakes</h1>

  <!-- the div class for our images-->


  <div class="shake">

    <img src="images/milkshake_image_1.jpg" alt="image of a chocolate milkshake">

  </div>


  <!-- our div class for the introduction line-->

  <div class="intro">

    <p>When the sun is out and the heat is beating down on you there is nothing as good as a nice cool milkshake. they come in many varietys</p>

  </div>


  <!-- div class for our body structure-->

  <div class="prime">

    <h2>What is a milkshake</h2>


    <!-- intro sentence-->

    <p>A milkshake it is a nice cold drink made with milk and a flavor of your choosing and ice cream mixed until its nice and creamy.</p>


    <!-- start of body: section 1-->

    <h2>History of the milkshake</h2>



    <p>It was during the (1870's-1900's) there was 2 diffrent types of shakes a normal shake and a milkshake but they were very different from each other. the first milkshake made used whole milk, vanilla or stawberry and nutmeg and then you span it for

      2 to 3 minutes, you get a frothy beverage that was very nice to drink. it is also belived to have started drive throughs.</p>


    <p> the way milkshakes use to be mixed was with a mechanical shakers they were built soley for mixing milkshakes and they took 2 to 3 minutes to mix a shake and the original flavours were chocolate, vanilla pineapple and coffee they were the main ones

      you would find there are others but they werent as common.</p>


    <!-- new section begins: section 2-->

    <h2>The best flavor of milkshake</h2>


    <p>now that is a question not so easily answered as everone has different opinons on which flavor is the best my favorite is chocolate or vanilla depends on my mood but for someone else that could be mint or strawberry so thats all on you as i can not

      tell you which is the best.</p>


    <!-- new section begins: section 3-->

    <h2>What is the perfect thickness</h2>


    <p>The 3 most common thicknesses you will hear about is thin,regular or thick.

    </p>


    <!-- are list that we will make collapsable through java-->

    <ol>

      <li>thin its more of a liquid and light.</li>

      <li>regular its a nice consistency of light and thick.</li>

      <li>thick which is my personal favorite it more along the lines of just being ice cream and its much heavier then the other 2.</li>

    </ol>


    <!-- sources for our milkshake stuff-->

    <h2>Sources</h2>

    <p>

      the art of drink:

      <a href="https://www.artofdrink.com/soda/history-of-the-milkshake">https://www.artofdrink.com/soda/history-of-the-milkshake</a></p>

  </div>


  <!-- our 2nd image-->

  <div class="shake">

    <img src="images/milkshake_image-2.jpg" width="400px" alt="2nd image of a milkshake with different topings">

  </div>


  <div id="square"></div>


  <button type="button" id="clickMe">Click Me</button>




</body>



</html>


查看完整回答
反對(duì) 回復(fù) 2022-10-27
?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

您正試圖在 HTML 元素被解析到內(nèi)存之前對(duì)其進(jìn)行定位和引用。將您的<script>引用移至結(jié)束body標(biāo)記之前。


在下面的代碼中,我手動(dòng)插入了您將要引用的代碼,但只要您將script標(biāo)簽保留在我下面的位置,您就可以刪除 JavaScript 并將 .js 引用添加到script.


/* color for webpage*/

html{

    background: silver;

    }

/* setting for heading 1 */

h1{

    color: saddlebrown;

    font-family: Helvetica, sans-serif;

    text-align: center;

    font-size: 55px;

}

/* settings for heading 2 */

h2{

    font-size: 30px;

    color: #D2691E;

    font-family: Helvetica, sans-serif;

}

/* settings for the introduction line */

.intro{

    text-align: center;

    padding-bottom: 1em;

    font-family: arial;

    margin: auto;

    max-width: 1100px;

    line-height: 2;

    font-size: 20px;

   

    

}

/* settings for images */

.shake {

   display:block;

margin-left: auto;

    margin-right: auto;

    width: 30%;

}

/* settings for body structure */

.prime{

    padding-bottom: 1em;

    font-family: arial;

    margin-right: auto;

    max-width: 900px

}


#square{

    width: 100px;

    height: 100px;

    border: 2px inset gray;

    margin-bottom: 1em;

}



button{

    padding: .5em 2em;

}

<!DOCTYPE html>

<!-- will need to make java, and css files and link them-->

<html>

    <!--website title and attributes-->

<head>

    <title>Milkshakes</title>

    <meta charset="UTF-8">

    <link rel="stylesheet" href="main.css">

    </head>

<!-- make seprate class for each elment here-->

    <body>

        <h1>Milkshakes</h1>

        <!-- the div class for our images-->

        

        <div class="shake">

        <img src="images/milkshake_image_1.jpg" alt="image of a chocolate milkshake">

            </div>

        

        <!-- our div class for the introduction line-->

        <div class="intro">

        <p>When the sun is out and the heat is beating down on you there is nothing as good as a nice cool milkshake. they come in many varietys</p>

        </div>

        

        <!-- div class for our body structure-->

         <div class="prime">

        <h2>What is a milkshake</h2>

        

       <!-- intro sentence-->

        <p>A milkshake it is a nice cold drink made with milk and a flavor of your choosing and ice cream mixed until its nice and creamy.</p>

             

        <!-- start of body: section 1-->

        <h2>History of the milkshake</h2>

       

        

        <p>It was during the (1870's-1900's) there was 2 diffrent types of shakes a normal shake and a milkshake but they were very different from each other. the first milkshake made used whole milk, vanilla or stawberry and nutmeg and then you span it for 2 to 3 minutes, you get a frothy beverage that was very nice to drink. it is also belived to have started drive throughs.</p>

            

        <p> the way milkshakes use to be mixed was with a mechanical shakers they were built soley for mixing milkshakes and they took 2 to 3 minutes to mix a shake and the original flavours were chocolate, vanilla pineapple and coffee they were the main ones you would find there are others but they werent as common.</p>

            

             <!-- new section begins: section 2-->

        <h2>The best flavor of milkshake</h2>

            

            <p>now that is a question not so easily answered as everone has different opinons on which flavor is the best my favorite is chocolate or vanilla depends on my mood but for someone else that could be mint or strawberry so thats all on you as i can not tell you which is the best.</p>

            

             <!-- new section begins: section 3-->

            <h2>What is the perfect thickness</h2>

            

            <p>The 3 most common thicknesses you will hear about is thin,regular or thick. 

            </p>

            

            <!-- are list that we will make collapsable through java-->

            <ol>

            <li>thin its more of a liquid and light.</li>

            <li>regular its a nice consistency of light and thick.</li>    

            <li>thick which is my personal favorite it more along the lines of just being ice cream and its much heavier then the other 2.</li>

            </ol>

            

            <!-- sources for our milkshake stuff-->

            <h2>Sources</h2>

            <p>

                the art of drink:

                <a href="https://www.artofdrink.com/soda/history-of-the-milkshake">https://www.artofdrink.com/soda/history-of-the-milkshake</a></p>

        </div>

        

        <!-- our 2nd image-->

       <div class="shake">

        <img src="images/milkshake_image-2.jpg" width= "400px" alt="2nd image of a milkshake with different topings">

        </div>  

        

        <div id="square"></div>

        

        <button type="button" id="clickMe">Click Me</button>

        

     <script>

/*variables used in index.html document*/

var square = document.getElementById("square")

var clickMe = document.getElementById('clickMe');


/*What the button is suppose to do*/

function doDemo() {  

    var button = this;

    square.style.backgroundColor = "#ff4545";

    button.setAttribute("diabled", "true");

    setTimeout(clearDemo, 2000, button);

}

/*removes the attributes when you click the button again*/

function clearDemo (button) {

    var square = document.getElementById("square");

    square.style.backgroundColor = "transparent";

    button.removeAttribute("diabled");

}


clickMe.onclick = doDemo;     

     </script>       

        

    </body>

    


</html>


查看完整回答
反對(duì) 回復(fù) 2022-10-27
  • 3 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)