JavaScript output
JavaScript can output data in 4 different ways:
Use window.alert() to pop up an alert box.
Use the document.write() method to write the content into the HTML document.
Use innerHTML to write to HTML elements.
Use console.log() to write to the browser's console.
#window.alert()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script src="/static/js/abc.js"></script><script>
function myFunction()
{
window.alert("Hello! 这是一个按钮");
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert box">
</body>
</html>document.write()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
<h1>Head</h1>
<script>
document.write('<p>hello document</p>');
</script>
<h2>Tail</h2>
</html>innerHTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
function getInnerHTML(){
alert(document.getElementById("test").innerHTML);
}
</script>
</head>
<body>
<p id="test"><span color="#000">php中文网</span></p>
<input type="button" onclick="getInnerHTML()" value="点击" />
</body>
</html>console.log()
If your browser supports debugging, you can use the console.log() method Display JavaScript value in browser. Use F12 in the browser to enable debugging mode, and click the "Console" menu in the debugging window.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script type="text/javascript"> a = 5; b = 6; c = a + b; console.log(c); </script> </head> <body> <p>在浏览器中使用F12来调试,在调试窗口中点击 "Console"</p> </body> </html>
new file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script src="/static/js/abc.js"></script><script>
function myFunction()
{
window.alert("Hello! 这是一个按钮");
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert box">
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)















