foreach equivalent of php in jquery?

前端 未结 5 1755
再見小時候
再見小時候 2020-12-31 06:58

Is there a foreach code in JQuery as in PHP? I have a code in php,like

       
if(\"

        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 07:34

    Jquery operating on selectors:

    $('a').each(function() {
        $(this).click(function(e) {
           e.preventDefault()
           var href = this.href;
           open(href);
        });
        // operate on the anchor node.
    });
    

    jQuery direct $.each:

    var a = ['one', 'two'];
    
    $.each(a, function() {
        alert(this)
    });
    

    JS: Vanilla for loop

     for ( var i = 0, len = 10; i

    JS #2: vanilla for

     var humanLimbs = ['arms', 'legs'];
     for ( var limb in humanLimbs ) {
         if ( humanLimbs.hasOwnProperty(limb) ) {
            alert( limb )
         }
     }
    

    Js #3: infinite loop

    for (;;) { alert(1) } // dont try this :p
    

提交回复
热议问题