首页 > 解决方案 > jquery检查是否检查了3个复选框在iphone上不起作用

问题描述

所以我目前正忙于在人们可以对 3 个想法进行投票的网站上工作。
我做了一个功能,当有人没有选择 3 个想法进行投票时,投票提交按钮被禁用,当他/她选择 3 时,提交变得可用。
问题是它在 android 手机上工作得非常好,但在 iphone 上,当我选择 3 时它保持禁用状态,但当我从 3 切换到 2 或 4 时它变得可用。
但这不是应该发生的事情,任何人都知道可能是什么问题.

下面是我在 JQuery 中的函数

$('body').on('change','#nieuwetrofeestemmen_table',function () {
   var checked = getCheckedRows('nieuwetrofeestemmen_table');
   if(checked.length < 3 || checked.length >3){
       $('.btnStemmen').prop('disabled', true);
   }
   else {
       $('.btnStemmen').prop('disabled', false);
   }
});

提前致谢

标签: jquerylaravel-5

解决方案


无论设备如何,这都应该有效。但是用你的Iphone检查一下。确保您在设置中启用了 javascript。

$('#checkboxes').on('change',function () {
   var checked = $('#checkboxes').find('input[type=checkbox]:checked');
   if(checked.length !== 3){
       $('.btnStemmen').prop('disabled', true);
   }
   else {
       $('.btnStemmen').prop('disabled', false);
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="checkboxes">
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
<input type="checkbox">A</input>
</div>
<button class="btnStemmen" disabled>Stemmen</button>

顺便说一句:if(checked.length !== 3)像你的一样工作,if(checked.length < 3 || checked.length > 3)但看起来更干净。


推荐阅读