jquery - 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);
}
});
提前致谢
解决方案
无论设备如何,这都应该有效。但是用你的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)
但看起来更干净。
推荐阅读
- python - Python Selenium 和 BS
- github - 删除 VSC 项目和 Github 之间的连接
- python - bash 中的 subprocess.call() exec 命令,但我使用的是 zsh?
- react-native - 垂直居中滚动视图
- html - 图片无法显示
- java - 如果使用java符合某些条件,则提取列表中的数字并将其放入其他列表元素
- sql - 对几千个搜索词进行数据库对象搜索的最佳方法
- python - 光标插入返回内存不足错误
- java - OpenCV BirdEyeView:如何正确设置透视变换的点?
- spring - 在自定义登录页面登录后找不到 404 页面