实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p id="p1">Click the button to locate where "locate" first occurs.</p>
6
<p id="p2">0</p>
7
<button onclick="myFunction()">Try it</button>
8
9
<script>
10
function myFunction()
11
{
12
var str=document.getElementById("p1").innerHTML;
13
var n=str.indexOf("locate");
14
document.getElementById("p2").innerHTML=n+1;
15
}
16
</script>
17
18
</body>
19
</html>
20
21