Javascript: Web

本文介绍了HTML中<script>标签的使用,包括基本格式、模块加载、async和defer属性的差异。同时,讲解了DOM的概念,如何用JavaScript操作DOM元素,以及创建和修改文档结构的方法。
摘要由CSDN通过智能技术生成

<script>

Used to included the javascript code in HTML.

Basic format: 

<script src= "scripts/digital_clock.js"></script>

module

If you have used modules in your code, i.e. import, export directives, made the script type as module.

<script type="module"></script>
  • defer: All of the modules the script imports will be loaded after the template HTML is rendered
    • can be overriden by async attribute

default loading method

  • document.write() -- synchronous, execute the script in the middle of template redendering

async & defer

  • <script defer src="deferred.js"></script>
    • defer the script execution till after template rendered
    • All scripts still run in order
  • <script async src="async.js"></script>
    • executes the script immediately, not blocking the rendering
    • Order not guranteed

on demand loading

  • Create a script tag from javascript

DOM

Represent the HTML document, mirror the tree structure

  • There is a JavaScript class corresponding to each HTML tag type
    • <body> = HTMLBodyElement
    • <table> = HTMLTableElement
  • DOM API includes methods for
    • creating new Element and Text nodes
    • inserting them into the document as children of other Element objects
    • moving elements within the document
    • removing elements entirely

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值