日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Javascript-7对象:字符串、时间

發布時間:2023/12/10 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Javascript-7对象:字符串、时间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JavaScript-7對象:字符串、時間

?????? 字符串(String)對象

????????????? Javascript是面向對象的編程語言,我們可以定義自己的對象和變量類型。

?????? 計算字符串長度

var txt="Hello world!"

document.write(txt.length)

結果為:12

?????? 字符串樣式

????????????? document.write("<p>Big: " + txt.big() + "</p>")

document.write("<p>Small: " + txt.small() + "</p>")

document.write("<p>Bold: " + txt.bold() + "</p>")

document.write("<p>Italic: " + txt.italics() + "</p>")

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

document.write("<p>Fixed: " + txt.fixed() + "</p>")

document.write("<p>Strike: " + txt.strike() + "</p>")

document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")

document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")

document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")

document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")

document.write("<p>Subscript: " + txt.sub() + "</p>")

document.write("<p>Superscript: " + txt.sup() + "</p>")

document.write("<p>Link: " + txt.link("http://www.baidu.com") + "</p>")

?????? 相信學習過HTML的不還沒有忘記那些關鍵字吧,沒錯,就是對應的意思。

?

?????? indexOf() 用來測定字符串中的字符首次出現的位置

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

????????????? 結果為:6

?????? match() 搜索字符串中的字符,找到返回此字符,否則返回null

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

????????????? 結果為:world

?????? replace()替換目標字符

document.write(txt.replace(/World/,"BeiJing"))

結果為:Hello BeiJing

?

?????? 日期date對象

????????????? Date對象用于處理日期和時間。

????????????? 顯示當前時間:

???????????????????? document.write(Date())

????????????? 設定時間:

???????????????????? var myDate=new Date(2008,7,9)

???????????????????? 月份的參數是0-11,所以設置8月要寫成7。

????????????? gerTime() 獲得從1970到現在過了多少秒(計算機從1970開始初始值的)

???????????????????? var d = new Date();

?var t = d.getTime();

?var y = t/(1000*60*60*24*365);

?document.write(y);

以上計算了距離1970多少天。

????????????? getDate()獲取當前日期。getYear()獲取當前年份,getMonth獲取當前月份,getDay獲取當前星期

???????????????????? var d = new Date();

?var t = d.getDate();

?document.write(t);

????????????? setFullYear()設定年(月日),得到精確時間。

???????????????????? var d = new Date()

d.setFullYear(2011,2,14)? //可以只寫2011

document.write(d)

?????? ?????? getDay,如何顯示星期,而不是數字

???????????????????? var d=new Date()

var weekday=new Array(7)

weekday[0]="星期日"

weekday[1]="星期一"

weekday[2]="星期二"

weekday[3]="星期三"

weekday[4]="星期四"

weekday[5]="星期五"

weekday[6]="星期六"

document.write("今天是" + weekday[d.getDay()])

?

?

?

?

?

?

轉載于:https://blog.51cto.com/diesel/511988

總結

以上是生活随笔為你收集整理的Javascript-7对象:字符串、时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。