?? string對象.txt
字號:
String
1)字符串處理
var mystr="Look at This.";//索引從0開始
document.writeln(mystr.charAt(5)+"<BR>");//charAt返回指定位置的字符
document.writeln(mystr.substring(5,7)+"<BR>");//substring返回指定位置的字符串
document.writeln(mystr.indexOf("o")+"<BR>");//指定字符串的索引位置(從左向右搜索)
document.writeln(mystr.lastIndexOf("o")+"<BR>");//指定字符串的索引位置(從右向左搜索)
document.writeln(mystr.toLowerCase()+"<BR>");//把字符串轉(zhuǎn)化為小寫
document.writeln(mystr.toUpperCase()+"<BR>");//把字符串轉(zhuǎn)化為大寫
2)Web外觀處理
//字符特效
document.writeln(mystr.big()+"<BR>");//加大字號
document.writeln(mystr.small()+"<BR>");//減小字號
document.writeln(mystr.blink()+"<BR>");//閃爍(IE無效)
document.writeln(mystr.bold()+"<BR>");//黑體
document.writeln(mystr.fixed()+"<BR>");//等寬體
document.writeln(mystr.fontcolor("green")+"<BR>");//指定字體顏色
document.writeln(mystr.fontsize(12)+"<BR>");//指定字體大小
document.writeln(mystr.italics()+"<BR>");//斜體
document.writeln(mystr.strike()+"<BR>");//刪除線
document.writeln(mystr.sub()+"<BR>");//下標顯示(IE無效)
document.writeln(mystr.sup()+"<BR>");//上標顯示(IE無效)
//由于HTML用""來分隔字符串,如果要在HTML中使javscript語句,必須使用'自分隔自已的字符串
3)鏈接的處理
//把字符轉(zhuǎn)化為HTML鏈接
var linktext="Yahoo";
var URL="http://www.yahoo.com";
document.open();
document.write("This is"+linktext.link(URL)+"超級連接");
document.close();
4)其它函數(shù)
document.writeln(mystr.concat("water")+"<BR>");//字串連接
document.writeln(mystr.slice(5,8)+"<BR>");//獲得子串,第二個參數(shù)為+,表示從左起(不包含自身)
document.writeln(mystr.slice(5)+"<BR>");//省略第二個參數(shù),子串至末尾
document.writeln(mystr.slice(5,-2)+"<BR>");//第二個參數(shù)為-,表示從右起
//match() 用正則表達式搜索字符串
var r, re; // 聲明變量。
var s = "The rain in Spain falls mainly in the plain";
re = /ain/i; // 創(chuàng)建正則表達式模式。
r = s.match(re); // 嘗試匹配搜索字符串。
document.writeln(r+"<BR>");
re= /ain/ig; //帶g,尋找所有匹配
r=s.match(re);
document.writeln(r+"<BR>");
//找網(wǎng)址沒有實現(xiàn)
//replace() 字符替換,以match為基礎(chǔ)
r=s.replace(re,"mov");
document.writeln(r+"<BR>");
//search() 搜索字符串是否存在,以match為基礎(chǔ),索引位置,沒有找到則為-1
r=s.search(re);
document.writeln(r+"<BR>");
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -