JQuery--遍历--for循环,each循环,全局each&forof

    科技2023-10-19  94

    黑马程序员

    JQuery–遍历1–for循环

    JQuery–遍历2–each循环

    JQuery–遍历3–全局each&forof

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JQuery--遍历1--for循环</title> <script src="js/jquery-3.3.1.min.js"></script> </head> <body> <script> $(function () { var citys = $("#city li"); /*for(var i=0;i<citys.length;i++){ alert(i+':'+citys[i].innerHTML) }*/ /*citys.each(function () { alert(this.innerHTML); alert($(this).html()); })*/ /*citys.each(function (index,element) { //alert(index+":"+element.innerHTML); if ("上海"==$(element).html()){ return false; } alert(index+":"+$(element).html()); })*/ /*$.each(citys, function () { alert($(this).html()) })*/ for(li of citys){ alert($(li).html()); } }) </script> <ul id="city"> <li>北京</li> <li>上海</li> <li>深圳</li> <li>广东</li> </ul> <span id="show"></span> </body> </html>
    Processed: 0.024, SQL: 8