Home  >  Q&A  >  body text

Teacher, why can’t I run the code you taught me?

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
< ;title>Traverse jquery objects</title>
<script src="../jquery-3.3.1.js"></script>
<script>
$( "button").click(function () {
                                                                                                                                                                 .                More functions can be completed.
$("li").each(function (i) {
                    $(this).css("color","red").html(i "---" "www.php.cn");
});
})
     
                                                                                   ;button type="button" name="button">Please click to change color</button>
<ul>
;PHP Chinese website 02</li>
;/li>
</ul>
</body>
</html>

iUnicorniUnicorn2063 days ago1607

reply all(5)I'll reply

  • Alone88

    Alone882019-03-20 16:51:43

    If your js code is written on <body>, you need to add the entry function

    reply
    0
  • iUnicorn

    It should be unnecessary, just put the script code at the back. thanks for the reply

    iUnicorn · 2019-03-20 17:00:15
  • 小灰

    小灰2019-03-19 16:53:53

    <!DOCTYPE html>

    <html lang="zh-CN">

    <head>

    <meta charset="UTF -8">

    <title>Traverse jquery object</title>

    </head>

    <body>

    <button type="button" name="button">Please click to change color</button>

    <ul>

    <li>PHP Chinese website 01</li> ;

    <li>PHP Chinese website 02</li>

    <li>PHP Chinese website 03</li>

    <li>PHP Chinese website 04</li>

    <li>PHP Chinese website 05</li>

    </ul>

    </body>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

    <script>

    $("button").click(function () {

    //The above line of commented code can use this function to complete more functions.

    $("li") .each(function (i) {

    $(this).css("color","red").html(i+"---"+"www.php.cn");

    });

    })

    </script>

    </html>


    reply
    1
  • iUnicorn

    Thanks for the reply, I changed the location and solved it. Thanks again! ! Haha~~

    iUnicorn · 2019-03-20 16:59:33
  • Cancelreply