直播平台源代码,JavaScript 的四种调试输出方式

建站教程3年前 (2022)更新 ypng
37 0 0

直播平台源代码,JavaScript 的四种调试输出方式
一、使用 innerHTML
如需访问 HTML 元素,JavaScript 可使用 document.getElementById(id) 方法。

id 属性定义 HTML 元素。innerHTML 属性定义 HTML 内容:

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h1>我的第一张网页</h1>
  5. <p>我的第一个段落</p>
  6. <p id="demo"></p> 
  7. <script>
  8. document.getElementById("demo").innerHTML = 5 + 6;
  9. </script>
  10. </body>
  11. </html>

提示:更改 HTML 元素的 innerHTML 属性是在 HTML 中显示数据的常用方法。

二、使用 document.write()
向网页中写入数据:

  1.  <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h1>我的第一张网页</h1>
  5. <p>我的第一个段落</p>
  6. <button onclick="document.write(5 + 6)">试一试</button>
  7. </body>
  8. </html>
  9. <!DOCTYPE html>
  10. <html>
  11. <body>
  12. <h1>我的第一张网页</h1>
  13. <p>我的第一个段落</p>
  14. <button onclick="document.write(5 + 6)">试一试</button>
  15. </body>
  16. </html>

注意:在 HTML 文档完全加载后使用 document.write() 将删除所有已有的 HTML ,document.write() 方法仅用于测试
三.使用 window.alert()
使用警告框来显示数据

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h1>我的第一张网页</h1>
  5. <p>我的第一个段落</p>
  6. <script>
  7. window.alert(5 + 6);
  8. </script>
  9. </body>
  10. </html>

四 .使用 console.log() (个人推荐最方便调试的方式)
在浏览器中,您可使用 console.log() 方法来显示数据。

请通过 F12 来激活浏览器控制台,并在菜单中选择“控制台”。

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h1>我的第一张网页</h1>
  5. <p>我的第一个段落</p>
  6. <script>
  7. console.log(5 + 6);
  8. </script>
  9. </body>
  10. <html>

以上就是 直播平台源代码,JavaScript 的四种调试输出方式

原文地址:https://blog.csdn.net/yb1314111/article/details/125720235

© 版权声明

相关文章

暂无评论

暂无评论...