开发者

How to get the value of every select box of the same class in Jquery

开发者 https://www.devze.com 2023-02-28 18:11 出处:网络
So I have several select boxes like this: <select class=\"designer\"> <option>300</option>

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.

0

精彩评论

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