看看这个我做了一个类,这样循环起来会更容易
http://jsfiddle.net/6SftR/
JS代码
var sum = 0 ;
var nums = 0;
$('.slider').bind({
slidechange : function(event,ui) {
sum = 0;
nums = 0;
$('.slider').each(function(){
var value = $( this ).slider( "option", "value" );
if(value > 0 )
{
sum += value ;
nums++;
}
});
var avg = sum / nums ;
$('.average').val(Math.floor(avg));
console.log(avg);
}
}).slider();
代码
<div class="slider"></div>
<div class="slider"></div>
<div class="slider"></div>
<div class="slider"></div>
<div class="slider"></div>
<div class="slider"></div>
<input type="text" class="average" name="pm_overall_score" id="pm_overall_score" value="" size="30">
我希望这个能帮上忙