源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <style> div { color: blue; } div#five { color: red; } </style> <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script> </head> <body> <div id="one"></div> <div id="two"></div> <div id="three"></div> <div id="four"></div> <div id="five"></div> <script> $(function () { var arr = [ "one", "two", "three", "four", "five" ]; var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 }; $.each( arr, function( i, val ) { $( "#" + val ).text( "我的是 " + val + "." ); // 在 "three" 之后将停止运行 return ( val !== "three" ); }); $.each( obj, function( i, val ) { $( "#" + i ).append( document.createTextNode( " - " + val ) ); }); }) </script> </body> </html>
运行结果: