主题:
3024-night
ambiance-mobile
ambiance
base16-dark
blackboard
cobalt
eclipse
erlang-dark
lesser-dark
mbo
mdn-like
midnight
monokai
neat
neo
night
paraiso-dark
pastel-on-dark
rubyblue
solarized
the-matrix
tomorrow-night-eighties
vibrant-ink
新窗口
视图:
左侧面板
HTML
CSS
JS
预览
F11(全屏显示选中的编辑器)
查看更多帮助信息
相关文章:
全局jQuery.each() 函数详解
代码类型:
默认(HTML/CSS/JS)
HTML混合(单页)
PHP
Java
C#
C++
C
SQL
杂项:
启用CSS/JS语法检查
监测脚本运行错误
禁止库文件重复
文档类型:
HTML5
HTML 4.01 Strict
HTML 4.01 Transitional
HTML 4.01 Frameset
XHTML 1.0 Strict
XHTML 1.0 Transitional
XHTML 1.0 Frameset
无
JS库文件:
无
jQuery 1.11.1
jQuery 2.1.1
jQuery 1.10.2
jQuery 1.9.1
jQuery 1.8.3
jQuery 1.7.2
jQuery 1.6.4
jQuery 1.5.2
jQuery 1.4.4
jQuery 1.3.2
jQuery 1.2.6
手动添加:
jQuery 1.11.1
<div id="n1"> <div id="n2"> <ul id="n3"> <li id="n4">item1</li> <li id="n5">item2</li> <li id="n6">item3</li> </ul> </div> </div> <form id="demoForm"> <input name="goods_weight" type="checkbox" value="20">A(20kg)<br> <input name="goods_weight" type="checkbox" value="33">B(33kg)<br> <input name="goods_weight" type="checkbox" value="36">C(36kg)<br> <input name="goods_weight" type="checkbox" value="49">D(49kg)<br> <input name="goods_weight" type="checkbox" value="56">E(56kg)<br> <input name="goods_weight" type="checkbox" value="78">F(78kg)<br> <input id="btnBuy" type="button" value="订购"> </form>
//在当前页面内追加换行标签和指定的HTML内容 function w( html ){ $(document.body).append("<br/>" + html); } //遍历数组元素 $.each( [1, 2, 3] , function(i, item){ w("索引=" + i + "; 元素=" + item); } ); // 遍历对象属性 $.each( { name: "张三", age: 18 } , function(property, value){ w("属性名=" + property + "; 属性值=" + value); } ); var array = []; array[2] = "Code"; array[4] = "Player"; // 会遍历索引为0、1、2、3、4的元素,其中0、1、3的元素是undefined $.each( array , function(i, item){ w("索引=" + i + "; 元素=" + item); } ); $.each( $("ul li"), function(index, element){ // this === element $(element).html( "编号" + (index + 1) ); }); $("#btn").click(function(){ var weight = 0; $.each( $("[name=goods_weight]:checked"), function(){ weight += parseInt(this.value); if(weight > 100){ return false; } }); if(weight <= 0){ alert("没有选择任何商品!"); }else if(weight > 100){ alert("一次订购的商品重量不能超过100kg!"); }else{ // 订购商品 alert("订购商品成功!"); } });