大佬教程收集整理的这篇文章主要介绍了jQuery .each() – 实用?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// Loop over each link. $( "#links a.number" ).each( // For each number,run this code. The "inTindex" is the // loop iteration index on the current element. function( inTindex ){ // Bind the onclick event to simply alert the iteration index value. $( this ).bind ("click",function(){ alert( "numbered index: " + inTindex ); }); });
核心/每个
示例:在页面上创建所有href的csv。 (对匹配的DOM元素进行迭代,“this”表示当前元素)
var hrefs = ""; $("a").each(function() { var href = $(this).attr('href'); if (href != undefined && href != "") { hrefs = hrefs + (hrefs.length > 0 ? "," + href : href); } }); alert(hrefs);
实用程序/ jQuery.each
迭代数组或对象的元素:(通过:
jQuery Documentation)
$.each( { name: "John",lang: "JS" },function(i,n){ alert( "Name: " + i + ",Value: " + n ); }); $.each( [0,1,2],n){ alert( "Item #" + i + ": " + n ); });
以上是大佬教程为你收集整理的jQuery .each() – 实用?全部内容,希望文章能够帮你解决jQuery .each() – 实用?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。