How to get the value of every select box of the same class in Jquery
So I have several select boxes like this:
<select class="designer">
<option>300</option>
<option>3422</option>
</select>
<selec开发者_高级运维t class="designer">
<option>5645</option>
<option>8323</option>
<option>3920</option>
</select>
All of them are of the class name "designer"
What I want to do is get the currently selected option as a value and add them all into one variable.
e.g.
var finalvalue = $('.designer').val() + $('.designer').val()
So all of the values of the designer select boxes added together to form the final value of the numbers.
Hope that makes sense.
Thanks
var total = 0;
$('.designer').each(function(){ total+=parseInt($(this).val()); });
Ideally this could be implemented with fold, but JS doesn't have that natively (nor does jQuery). It's simple to implement, however.
精彩评论