JS基礎(chǔ)整理 -1

1 所有JavaScript數(shù)字均為64位,整數(shù)(不使用小數(shù)點(diǎn)或指數(shù)計(jì)數(shù)法)最多為15位。

2 絕不要在數(shù)字前面寫零或x,除非需要進(jìn)行進(jìn)制轉(zhuǎn)換(0表示八進(jìn)制,x為十六進(jìn)制)。

3 JavaScript String(字符串)對(duì)象 實(shí)例

(1) 計(jì)算字符串的長(zhǎng)度? ??

var txt="Hello World!"??

document.write(txt.length)

(2)為字符串添加樣式

<body>

<script type = "text/javascript">

var txt="Hello World!"

document.write("Big: " + txt.big() + "")

document.write("Small: " + txt.small() + "")

document.write("Bold: " + txt.bold() + "")

document.write("Italic: " + txt.italics() + "")//斜體

document.write("Blink: " + txt.blink() + " (does not work in IE)")

document.write("Fixed: " + txt.fixed() + "")

document.write("Strike: " + txt.strike() + "")//刪除線

document.write("Fontcolor: " + txt.fontcolor("Red") + "")

document.write("Fontsize: " + txt.fontsize(16) + "")

document.write("Lowercase: " + txt.toLowerCase() + "")

document.write("Uppercase: " + txt.toUpperCase() + "")

document.write("Subscript: " + txt.sub() + "")//Subscript: Hello World!

document.write("Superscript: " + txt.sup() + "")//Superscript: Hello World!

document.write("Link: " + txt.link("http://www.w3school.com.cn") + "")//鏈接

</script>

</body>

4 indexOf()方法,用于定位字符串中某一個(gè)指定的字符首次出現(xiàn)的位置

<body>

<script type = "text/javascript">

var str="Hello world!"

document.write(str.indexOf("Hello") + "")

document.write(str.indexOf("World") + "")

document.write(str.indexOf("world"))

</script>

</body>

查看結(jié)果:

0

-1

6

5 match()方法,查找字符串中特定的字符,并且如果找到的話,則返回這個(gè)字符。

<body>

<script type = "text/javascript">

var str="Hello world!"

document.write(str.match("world") + "")

document.write(str.match("World") + "")

document.write(str.match("worlld") + "")

document.write(str.match("world!"))

</script>

</body>

查看結(jié)果

world

null

null

world!

6 替換字符串replace()方法,用于在字符串中用某些字符替換另一些字符

<body>

<script type = "text/javascript">

var str="Visit Microsoft!"

document.write(str.replace(/Microsoft/,"W3School"))

</script>

</body>

查看結(jié)果

Visit W3School!

7 日期對(duì)象用于處理日期和時(shí)間

![鬧鐘.png](http://upload-images.jianshu.io/upload_images/1122152-1ed2cc8d09b594b3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • js基礎(chǔ)篇(一)——數(shù)組的各種操作js基礎(chǔ)篇(三)——DOM的各種操作 1. 創(chuàng)建字符串 一個(gè)字符串用于存儲(chǔ)一系列...
    hanyuntao閱讀 972評(píng)論 0 5
  • 一、DOM 什么是DOM?Document Object Model(文檔對(duì)象模型)。DOM是針對(duì)HTML和XML...
    空谷悠閱讀 987評(píng)論 0 2
  • 一、JS前言 (1)認(rèn)識(shí)JS 也許你已經(jīng)了解HTML標(biāo)記(也稱為結(jié)構(gòu)),知道了CSS樣式(也稱為表示),會(huì)使用HT...
    凜0_0閱讀 2,807評(píng)論 0 8
  • JavaScript 參考手冊(cè)這個(gè)鏈接要參考,多使用 JavaScript 中的所有事物都是對(duì)象:字符串、數(shù)值、數(shù)...
    松哥888閱讀 440評(píng)論 0 1
  • 1.JavaScript 中的所有事物都是對(duì)象:字符串、數(shù)值、數(shù)組、函數(shù)... 此外,JavaScript 允許自...
    ancientear閱讀 299評(píng)論 0 2