如果小于 Max,则通过消除最少的用户将值除以其他值
Divide the value anong others if is lesser then Max by eliminating the least user
我试图找到在 value_votes class 上的值小于所有用户的最少用户,方法是使用用户 class 的值作为 value_votes class 在每个条件下将该值分配给剩余的其他用户,直到达到最大值通过消除每个用户然后使用公式是最小用户的 value_votes 除以剩余else 条件下的用户计数
localStorage.setItem('max_value','6');
$(".users").each(function () {
var users_id = $(this).val();
var User_Vote_count = $('#'+users_id+'').val();
var max_value = localStorage.getItem('max_value');
if (User_Vote_count > max_value) {
alert(users_id);
} else if(User_Vote_count == max_value) {
alert(users_id);
}
});
HTML
<input type="text" value="A9AH98" class="users">
<input type="text" value="16B9BH" class="users">
<input type="text" value="CC9GHF" class="users">
<input type="text" value="A9D9G5" class="users">
<input type="text" class="value_votes" id="A9AH98" value="3">
<input type="text" class="value_votes" id="16B9BH" value="1">
<input type="text" class="value_votes" id="CC9GHF" value="4">
<input type="text" class="value_votes" id="A9D9G5" value="5">
正如 jsfiddle 中所讨论的,我在这里发布代码:
localStorage.setItem('max_value','6');
var minValue;
var minItem;
//searching for minimum value among value inputs
$(".value").each(function() {
var val = parseInt($(this).val(), 10);
if (val && (!minItem || val < minValue)) {
minItem = this;
minValue = val;
}
});
var minValId = $(minItem).attr("id");
console.log(minValId);
//searching for .user textboxes where value is not equal
var remainingUserElements = $("input.users:not([value='"+minValId+"'])");
console.log(remainingValueElements);
//searching for .value textboxes where id is not equal
var remainingValueElements = $("input.value:not([id='"+minValId+"'])");
console.log(remainingUserElements);
var maxValue = parseInt(localStorage.getItem('max_value'), 10);
console.log(maxValue);
//searching for .value elements where id is >= maxValue
var geValueElements = remainingValueElements.filter(function(){
return parseInt($(this).val(), 10) >= maxValue;
});
geValueElements.each(function(){
//printing all values that are greater or equal to maxValue
console.log($(this).val());
});
我试图找到在 value_votes class 上的值小于所有用户的最少用户,方法是使用用户 class 的值作为 value_votes class 在每个条件下将该值分配给剩余的其他用户,直到达到最大值通过消除每个用户然后使用公式是最小用户的 value_votes 除以剩余else 条件下的用户计数
localStorage.setItem('max_value','6');
$(".users").each(function () {
var users_id = $(this).val();
var User_Vote_count = $('#'+users_id+'').val();
var max_value = localStorage.getItem('max_value');
if (User_Vote_count > max_value) {
alert(users_id);
} else if(User_Vote_count == max_value) {
alert(users_id);
}
});
HTML
<input type="text" value="A9AH98" class="users">
<input type="text" value="16B9BH" class="users">
<input type="text" value="CC9GHF" class="users">
<input type="text" value="A9D9G5" class="users">
<input type="text" class="value_votes" id="A9AH98" value="3">
<input type="text" class="value_votes" id="16B9BH" value="1">
<input type="text" class="value_votes" id="CC9GHF" value="4">
<input type="text" class="value_votes" id="A9D9G5" value="5">
正如 jsfiddle 中所讨论的,我在这里发布代码:
localStorage.setItem('max_value','6');
var minValue;
var minItem;
//searching for minimum value among value inputs
$(".value").each(function() {
var val = parseInt($(this).val(), 10);
if (val && (!minItem || val < minValue)) {
minItem = this;
minValue = val;
}
});
var minValId = $(minItem).attr("id");
console.log(minValId);
//searching for .user textboxes where value is not equal
var remainingUserElements = $("input.users:not([value='"+minValId+"'])");
console.log(remainingValueElements);
//searching for .value textboxes where id is not equal
var remainingValueElements = $("input.value:not([id='"+minValId+"'])");
console.log(remainingUserElements);
var maxValue = parseInt(localStorage.getItem('max_value'), 10);
console.log(maxValue);
//searching for .value elements where id is >= maxValue
var geValueElements = remainingValueElements.filter(function(){
return parseInt($(this).val(), 10) >= maxValue;
});
geValueElements.each(function(){
//printing all values that are greater or equal to maxValue
console.log($(this).val());
});