xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>JavaScript indexOf() 方法 - 基础教程(div.cn)</title>
<body>
<h1>JavaScript indexOf() 方法</h1>
<p>单击按钮以显示字符串中字符" L"的位置,从位置6开始搜索:</p>
<button onclick="myFunc()">Click</button>
<p id="x"></p>
<script>
function myFunc() {
var str = 'HELLO WORLD HELLO';
document.getElementById('x').innerHTML = str.indexOf('L', 6);
}
</script>
</body>
</html>