i need to do array and then send in php file with help ajax. I have code:
$(function() {
$('.photo-user-change').bind('click', function(){
var hasclass = $(this).hasClass('active');
if(hasclass == true) {
$(this).removeClass('active');
} else {
$(this).addClass('active');
var iwa = $('.active').attr('id');
alert(iwa);
}
});
});
and html:
<ul>
<li class="photo-user-change" id="1">1</li>
<li class="photo-user-change" id="2">2</li>
<li class="photo-user-change" id="3">3</li>
</ul>
When added class 'active' need introduce ID into an开发者_如何学编程 array and then sent this array in php file. ID maybe a few.
How do this? I need create multi selector. thanks.
Here's a quick way to get all elements with the class active
and photo-user-change
and create a comma separated list of their id
attribute. This could easily be converted to JSON format - for your PHP web-service. You would place this right before you fire off the web service call.
var ids = $('.photo-user-change.active').map(function() {
return this.id;
}).get().join(',');
alert(ids);
See it in action - http://jsfiddle.net/XSRUb/
精彩评论