Looping through in jQuery
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();
});
});
}
精彩评论