1
<p id="demo">单击按钮来定位指定文本首次出现的位置。</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var str = "Hello world, welcome to the universe.";
6
var n = str.indexOf("welcome");
7
document.getElementById("demo").innerHTML = n;
8
}
9
</script>