Two commonly used client-side output methods in JavaScript

Two commonly used client output methods


document.write(str)

  • Description: In the <body> tag of the web page, output the content of str.

  • Document means "document", which is the entire web page.

  • Document is a document object that represents the entire web page.

  • write() is an output method of the document object.

  • "." Decimal point: Call the object's method through the decimal point (.).

  • str: ​​Indicates the content to be output.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script type="text/javascript">
            //在<body>中输出一句话
            document.write("欢迎来到php.cn");
        </script>
    </head>
    <body>
    </body>
</html>


##window.alert(str)

  • Description: Pops up a warning dialog box in the current window, str is the content displayed in the dialog box.

  • window represents the current browser window, and window is a window object.

  • alert() method: Pops up a dialog box.

  • str: ​​Indicates the content to be output.

  • <!DOCTYPE HTML>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>php.cn</title>
            <script type="text/javascript">
                //打开网页时,弹出一个对话框
                window.alert("欢迎来到php.cn");
            </script>
        </head>
        <body>
        </body>
    </html>


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //在<body>中输出一句话 document.write("欢迎来到php.cn"); </script> </head> <body> </body> </html>
submitReset Code