使用JavaScript中的document.head属性获取文档<head>标记的ID。您可以尝试运行以下代码以在JavaScript中实现document.head属性-
<!DOCTYPE html> <html> <head id = "myid"> <title>JavaScript Example</title> </head> <body> <h1>Employee Information</h1> <form> Name: <input type = "text" name = "name" value = "Amit"><br> Subject: <input type = "text" name = "sub" value = "Java"> </form> <script> var a = document.head.id; document.write("<br>Head element id? "+a); </script> </body> </html>