HTML 练习js代码位置在head标签


方式一:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function(){
            var p=document.getElementById("id1")
            alert(p.nodeName)
        }
    </script>
</head>
<body>
<p id="id1">hello p</p>
</body>
</html>

方式二:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
    <script>
        $(document).ready(function(){
            $("p").css("color","red")
        })
    </script>
</head>
<body>
<p>hello world</p>
</body>
</html>

方式三:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
    <script>
        $(function(){
            $("p").css("color","red")
        })
    </script>
</head>
<body>
<p>hello world</p>
</body>
</html>

作者:klvchen,发布于:2019/03/15
原文:https://www.cnblogs.com/klvchen/p/10538210.html