js,jquery對string的一些操作(一)

js,jquery對string的一些操作(一)

整理一下對string的操作,方便之後的使用。


大體上我把string的操作分爲以下幾類:

  1. string的變形
  2. string提取分離(包含正則表達式)
  3. string和其他類型的轉化

暫時想到這三類,以後補充

string的變形

string的變形,實際上是指string在dom在不同的展現形式,例如放大變色。
實際代碼如下:

<script type="text/javascript">
            var txt = "Hello World!"
            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() + " (目前只有 Firefox 和 Opera 瀏覽器支持)</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.w3school.com.cn") + "</p>")

        </script>

效果圖
上圖是以上代碼的效果圖,可以十分清晰的看出在dom中str被對應的標籤包圍,實際上也是如此 我們用txt.big()來實驗一下。

$("#t").html(txt.big());//成功
console.log(txt.big());//<big>Hello World!</big>

這些方法的原理就是使用對應的標籤包圍string之後生成一個新的string對象。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章