复选框在触摸屏笔记本电脑上不起作用

时间:2018-09-18 07:43:12

标签: javascript jquery html

我有这样的复选框

<div class="icheck" style="margin-top: 5px !important;">
   <input type="checkbox"
   name="param_{{ $item->id }}"
   d="param_{{ $item->id }}"
   value="1"
   class="checkListItem"
   @if ($item->value == 1) checked @endif> 
</div>

选中后,将值设置为1,否则设置为0

$('body')
   .on('ifChecked', '.checkListItem', function(){
   $(this).val(1);
})

   .on('ifUnchecked', '.checkListItem', function(){
   $(this).val(0);
);

如果计算机不是触摸屏,则它在手机和计算机上的效果很好。在触摸屏计算机(Linux除外)上,它不会选中该复选框。

我尝试了点击事件,但没有成功

$('.checkListItem').on('click tap', function(e){
    console.log("works");
    e.preventDefault();
});

我有点迷路。更重要的是,因为它可以在装有Linux的触摸屏计算机上使用。可能是什么问题呢?如何使输入type =“ checkbox”在触摸屏计算机上工作?

谢谢!

1 个答案:

答案 0 :(得分:0)

enter image description here

$('.radiogroup').on('click touchend',function(){
 console.log("works");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="radiog" id="male" class="radiogroup" checked> Male
<input type="radio" name="radiog" id="femail" class="radiogroup"> Female

为触摸设备尝试Touchstarttouchend

$('.checkListItem').on('click touchstart touchend', function(e){
    console.log("works");
    e.preventDefault();
});
相关问题