fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <p id="demo">单击按钮显示“苹果”的位置:</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var fruits = ["香蕉", "橙子", "苹果", "甜瓜"]; var a = fruits.indexOf("苹果") var x=document.getElementById("demo"); x.innerHTML=a; } </script> <p><b>注意:</b>indexOf方法是在JavaScript 1.6中引入的,在IE 8或更早的版本中不可用。</p> </body> </html>
运行结果