Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>test</title>
</head>
<body>
    <p><b>search&replace string</b></p>
    <p id="demo">Welcome to JS world</p>
    <button onclick="myF()">點擊</button>
    <p id="demo3"></p>
    </br>
    <p>將college換成ELP</p>
    <button onclick="myF2()">Click</button>
    <p id="demo2">Cal State LA college</p>
    <script type="text/javascript">
    </script>
</body>
</html>
 
        function myF(){
            // let str = "Welcome to JS world";
            // let x = str.search("JS");
            let x =document.getElementById('demo').innerHTML.search("JS");
            document.getElementById('demo3').innerHTML = "Welcome to JS world的JS在第"+ x + "個起始位置";
        }
        function myF2(){
            // let str =document.getElementById('demo2').innerHTML;
            // let txt = str.replace("college","ELP");
            let txt = document.getElementById('demo2').innerHTML.replace("college","ELP");
            document.getElementById('demo2').innerHTML = txt;
        }
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
BruceeeYangpro
0viewers