fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <p id="demo">单击按钮显示从位置4开始查找的“苹果”第一次出现的位置:</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var fruits=["Banana","Orange","Apple","Mango","Banana","Orange","Apple","Mango"]; var a=fruits.indexOf("Apple",4) var x=document.getElementById("demo"); x.innerHTML=a; } </script> <p><b>注意:</b>indexOf方法是在JavaScript 1.6中被引进的,在IE 8 或更早的版本中不支持。 </p> </body> </html>
运行结果