Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ต้องระบุ text/javascript ในแท็ก <script> หรือไม่?


ในหน้า HTML ส่วนใหญ่ใช้ text/javascript ในแท็ก <script>

ตัวอย่าง:

<script type="text/javascript"> </script>

อย่างไรก็ตาม การนำ HTML5 มาใช้นำเสนอการปรับปรุงใหม่ๆ JavaScript กลายเป็นภาษาเริ่มต้นสำหรับ HTML5 และเบราว์เซอร์สมัยใหม่ ดังนั้นตอนนี้การเพิ่ม text/javascript ไม่จำเป็นในแท็ก <script>

<script> </script>

ตัวอย่าง

มาดูตัวอย่างใน jQuery

Live Demo

<html> 
    <head> 
        <title> jQuery Example</title> 
        <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
        <script> 
            $(document).ready(function(){ 
                document.write("Hello, World!"); 
            }); 
        </script> 
    </head> 
    <body> 
        <h1>Hello</h1> 
    </body> </html>