How make a loop using JQUERY?
I have a comma separated string. I split that string and assigned it to elements var. How can I loop that elements var?
$(document).ready(function(){
var element = $('#imageIds').val().split(",");
// how to loop this elements using jquery
}开发者_如何学Python);
You can use a standard loop like this:
var element = $('#imageIds').val().split(",");
var i;
for(i = 0; i < element.length; ++i) {
// Do stuff with element[i]
}
Or you can wrap element
as a jQuery object and use .each
or .map
or similar:
$($('#imageIds').val().split(",")).each(function(index, value) {
// Do stuff with value
});
for (var i = 0; i < element.length; i++) {
var tempVar = element[i];
}
something like this
Add jQuery click handler to mulitple elements?
This will help you..
You can use each function of jquery. It is used to iterate through element of an object. Here is nice tutorial.
精彩评论