源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>单击“试试”以显示字符串拆分后的第一个数组元素.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { var str = "a,b,c,d,e,f"; var arr = str.split(","); document.getElementById("demo").innerHTML = arr[0]; } </script> </body> </html>
运行结果