本文實(shí)例講述了JavaScript使用replace函數(shù)替換字符串的方法。分享給大家供大家參考。具體如下:
JavaScript通過replace函數(shù)替換字符串,下面的代碼將Visit Microsoft中的MicroSoft替換成VeVB.COm
<!DOCTYPE html><html><body><p>Click the button to replace "Microsoft" with "VeVB.COm" in the paragraph below:</p><p id="demo">Visit Microsoft!</p><button onclick="myFunction()">Try it</button><script>function myFunction(){var str=document.getElementById("demo").innerHTML;var n=str.replace("Microsoft","VeVB.COm");document.getElementById("demo").innerHTML=n;}</script></body></html>希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注