【问题标题】:Find the Least count number and then divide that number to specific remaing找到最少的计数,然后将该数字除以特定的剩余
【发布时间】:2015-10-01 15:48:07
【问题描述】:

我正在尝试将文本框值的每个值检查为本地存储 id 并获取该 id 的特定值,然后检查该值是否等于或大于我的示例中的特定值本地存储的值 Total_thrisholdvalue1价值

In this example the if condition works

Expecting some thing in else condition

我的问题是在检查值是否不大于或等于然后在其他条件下通过在每个条件下使用文本框的值它应该通过使用上面的文本框值作为本地存储 id 找到最小的数字,因为它是在 if 条件下执行,然后除以剩余 localstorage 数据值的数字并检查值是否匹配 Total_thrisholdvalue1 如果匹配,则警告该值否则消除另一个最不重要的值,直到该值等于或大于 Total_thrisholdvalue1

JS:

    localStorage.setItem('Total_thrisholdvalue1','4');
    localStorage.setItem('A9AH98','3');
    localStorage.setItem('16B9BH','2'); localStorage.setItem('CC9GHF','4'); 
localStorage.setItem('A9D9G5','5');


$(".candidateid").each(function () {
    var data = $(this).val();
    var candidates_count = localStorage.getItem(data);
    var Total_thrisholdvalue = localStorage.getItem('Total_thrisholdvalue1');

    if (candidates_count >= Total_thrisholdvalue) {

        alert(data );
    } else {

    }
});

HTML:

<input type="text" value="A9AH98" class="candidateid">
<input type="text" value="16B9BH" class="candidateid">
<input type="text" value="CC9GHF" class="candidateid">
<input type="text" value="A9D9G5" class="candidateid">

【问题讨论】:

  • 你的问题我不清楚。请用普通英语表达你的问题。最好用较短的句子。
  • @wintvelt 抱歉,通过使用文本框的每个值作为本地存储我获取每个本地存储 id 数据的值并使用 Total_thrisholdvalue 检查每个值,然后在检查是否没有值后听到问题大于Total_thrisholdvalue 然后通过使用与localstorage id 相同的texbox 并在获取时检查其数量小于最后一个的localstorage 数据,然后拆分给剩余的其他人,然后检查谁的值大于@987654330 @ 如果是,则警告该值,否则通过减少一个重复相同的值直到最后

标签: javascript jquery html


【解决方案1】:

localStorage 检索到的值是strings,因此&gt; 运算符不会像您预期的那样工作。首先将它们解析为整数:

var candidatesCount = parseint(localStorage.getItem(data), 10);
var totalThresholdvalue = parseint(localStorage.getItem('Total_thrisholdvalue1'), 10);

if (candidatesCount > totalThresholdvalue) {
   // etc.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多