欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-28 11:17:38
方式一: 方式二: 方式三: ......

方式一:

<!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>