本文實例講述了JavaScript搜索字符串并將搜索結果返回到字符串的方法。分享給大家供大家參考。具體如下:
javascript操作字符串帶有一個match方法用于搜索字符串,如果找到指定的字符串則返回搜索字符串,如果未找到則返回null,match方法區分大小寫
<!DOCTYPE html><html><body><script>var str="Hello world!";document.write(str.match("world") + "<br>");document.write(str.match("World") + "<br>");document.write(str.match("worlld") + "<br>");document.write(str.match("world!"));</script></body></html>返回結果:
world
null
null
world!
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答