second day for javascript

How to use javascript in HTML?

Use<script> input html.

Scriptdefine 6 property(属性)

async:forexpand script file download right nowdonot distrub other operation

Charsetdefinesrc character setlikeutf-8gbk

deferusingscript when file reloaded

languagenouse

srcexpandfile for use code

typereplacelanguage function

Twoways to use <script>

1.inhtml use javescript code

eg:

<scripttype=“text/javascript”>

functionsayhi()

{alert(“hi”);}

</script>

ifexplorer contains somelike </script> word.we should Escape(转义)</script> as <\script>

2.concludeexternal(外部)javascript file.

Eg:<scripttype=“text/javascript” src=“example.js”></script>

banfor html file

Labellocation

Intradition ways.all <script> element(元素)shouldbe in html<head>element.

Eg:

1.<!DOCTYPEhtml>

<html>

<head>

<title>eg</title>

<scripttype=”text/javascript”src=”example1.js”></script>

</head>

<body>contentin there</body>

</html>

2.formore speed to loading javascript

thereuse javascript in <body></body>

3.deferand ajax

<scripttype=”text/javascript” defer=”defer” scr=example1.js></script>

<scripttype=”text/javascript” defer=”defer” scr=example2.js></script>

whenopen explorer htmlrequire script First come, first servedsouse example1 for one

example2for twobutin reality life defer not obey this rulessobetter use only one defer script

anduse defer in html down

4.ajaxscript

asyncis different from defer. Because the async no first come,firstserverd.

5.inXHTML ways

extensiblehypertext markup language (可扩展的超文本标记语言)

rulesis so serious

usecdata conclude xml code

eg:

<scripttype=”text/javascript”><!CDATA

functioncompare(a,b)

if(a<B){…..................... }

]]></script>

ifexplorer doesn't support for xml

canuse javascript notes like //<!CDATA[

//]]>

Embedded(嵌入)code andexternal file

Advantagefor external file

maintainability(可维护性)

cache(缓存)oncefor two html

future

filemode

Doctype

1.quirksmode(混杂模式)

2.standardsmode(标准模式)

ifexplorer don‘t support for javascript

we’dbetter

<noscript>

<p>htmlrequire explorer support javascript

</noscript>

summary

Useexternal file for javascript need<script>src property for URL

thenis some rules for javascript/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值