Js基礎(chǔ)學(xué)習(xí)資料
更新時(shí)間:2010年11月23日 21:45:16 作者:
今天學(xué)習(xí)了哈很簡單的腳本語言----JavaScript,做了簡單的筆記。放在這里吧,方便翻出來看看。
1、防止不支持js的瀏覽器出問題可以這樣處理JS代碼
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
2、JS放置位置:
header:確保腳本被調(diào)用時(shí)已經(jīng)加載
body:頁面載入時(shí)就調(diào)用
外部js文件:不包含<script>標(biāo)簽
用法:<script src = "xxx.js">.....</sceipt>
3、注釋
單行://
多行:/*.....*/
4、=== 全等符號(hào) 表示類型和值都相等
5、三種提示框
警告:alert("alert");
確認(rèn):confirm("confirm");
提示:prompt("prompt","默認(rèn)值");
6、for in 聲明
for (變量 in 對象)
{
在此執(zhí)行代碼
}
7、正則表達(dá)式
test()方法:檢索字符串中的指定值,如果有返回True,否則False
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
exec()方法:檢索字符中中的指定值,如果有返回找到的值,否則返回null
var patt1=new RegExp("e");
document.write(patt1.exec("The best things in life are free"));
compile()方法:用于改變檢索模式和添加刪除第二個(gè)參數(shù)
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
2、JS放置位置:
header:確保腳本被調(diào)用時(shí)已經(jīng)加載
body:頁面載入時(shí)就調(diào)用
外部js文件:不包含<script>標(biāo)簽
用法:<script src = "xxx.js">.....</sceipt>
3、注釋
單行://
多行:/*.....*/
4、=== 全等符號(hào) 表示類型和值都相等
5、三種提示框
警告:alert("alert");
確認(rèn):confirm("confirm");
提示:prompt("prompt","默認(rèn)值");
6、for in 聲明
for (變量 in 對象)
{
在此執(zhí)行代碼
}
7、正則表達(dá)式
test()方法:檢索字符串中的指定值,如果有返回True,否則False
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
exec()方法:檢索字符中中的指定值,如果有返回找到的值,否則返回null
var patt1=new RegExp("e");
document.write(patt1.exec("The best things in life are free"));
compile()方法:用于改變檢索模式和添加刪除第二個(gè)參數(shù)
相關(guān)文章
javascript 實(shí)例詳解循環(huán)用法
假如您需要運(yùn)行代碼多次,且每次使用不同的值,那么循環(huán)(loop)相當(dāng)方便使用。本篇文章通過幾個(gè)實(shí)例來帶你掌握循環(huán)的用法2021-11-11