正文

Javascript String2009-11-17 19:17:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/akey307/50127.html

分享到:

Javascript String 1. search() var test = "what is happening here";var result = test.search("is"); 结果"result = 5" search()方法返回substring的index,如果没有找到,则返回-1 2. replace() var myVar = "Hello there";var newvar = myVar.replace("e", "E"); 结果newVar为"HEllo there". 注意: myVar的值不会被改变; 替换的时候只会替换到第一个匹配的值。如果想要全部替换,可以使用正则表达式。   3.格式化strings • big: Returns the string in big tags • blink: Returns the string in blink tags • bold: Returns the string in b tags • fixed: Returns the string in tt tags (for fixed-width display) • fontcolor: Returns the string in font tags with the color attribute set to the color you specify as an argument • fontsize: Returns the string in font tags with the size attribute set to the size you specify as an argument • italics: Returns the string in i tags • small: Returns the string in small tags • strike: Returns the string in strike tags (for a strikethrougheffect) • sub: Returns the string in sub tags (for a subscript effect) • sup: Returns the string in sup tags (for a superscript effect) • toLowerCase: Returns the string with all lowercase characters • toUpperCase: Returns the string with all upper case characters   <body> <script language=”JavaScript”> <!-- var myVariable = “Hello there”; document.write(myVariable.big() + “<br>”); document.write(myVariable.blink() + “<br>”); document.write(myVariable.bold() + “<br>”); document.write(myVariable.fixed() + “<br>”); document.write(myVariable.fontcolor(“red”) + “<br>”); document.write(myVariable.fontsize(“18pt”) + “<br>”); document.write(myVariable.italics() + “<br>”); document.write(myVariable.small() + “<br>”); document.write(myVariable.strike() + “<br>”); document.write(myVariable.sub() + “<br>”); document.write(myVariable.sup() + “<br>”); document.write(myVariable.toLowerCase() + “<br>”); document.write(myVariable.toUpperCase() + “<br>”); // --> </script> </body>

阅读(2596) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册