搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript indexOf() 方法 - 基础教程(div.cn)</title> <body> <h1>JavaScript indexOf() 方法</h1> <p>点击按钮,显示"Pollution"一词的位置:</p> <button onclick="myFunc()">Click</button> <p id="x"></p> <script> function myFunc() { var str = 'Air Pollution is introduction of chemicals to the atmosphere'; document.getElementById('x').innerHTML = str.indexOf('Pollution'); } </script> </body> </html>
运行结果