开发者

Looping through in jQuery

开发者 https://www.devze.com 2023-03-27 04:51 出处:网络
i have written following function in JS which is called on click of some element in Client Side.I want to loop thru in jQuery,but following code is not working.

i have written following function in JS which is called on click of some element in Client Side.I want to loop thru in jQuery,but following code is not working.

function HideShowMenu( pStart, pLength)

$(document).ready(function(){

    for ( i=pStart ; i <= pLength ; i++ ) {

        $('#tr_menu_'+i).show();
     } 

});

// return   
ret开发者_如何学编程urn;  
}   

How can i go about it?


$(document).ready(function(){
    HideShowMenu(0, 5);
});
function HideShowMenu(pStart, pLength) {
    for ( var i=pStart; i <= pLength; i++ ) {
        $('#tr_menu_' + i).show();
    } 
}   


You are misusing $(document).ready();. Correct way is something like this:

function HideShowMenu( pStart, pLength){
    for (var i=pStart ; i <= pLength ; i++ ) {
        $('#tr_menu_'+i).show();
    } 
}   

$(document).ready(function(){
    HideShowMenu(1,10);
});

$(document).ready() should be outside any other function.


$('#element').each(function(){
    $(this).show();
});


function HideShowMenu() {
    $(document).ready(function(){
        $('#tr_menu_').each(function() {
            $(this).show();
        });
    });
}   
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号