http://api.jqueryui.com/spinner/ http://api.jqueryui.com/spinner/
我正在尝试在我的网站中使用上面的 jQuery spinner(它的演示位于 API 底部)。
它在计算机上确实有效,但在移动设备上,每次单击向上/向下按钮时,键盘都会非常烦人地弹出。有可能阻止这种情况的发生吗?微调器并不能很好地响应 .on('click') 等本机函数,而是有自己的函数。
如何修改代码,以便仅在单击文本框时显示键盘,而不显示上下按钮?
这是我的尝试,它不起作用:
$( function() {
$('.ui-spinner a').on('click', function() {
$(':focus').blur();
});
}) // Updated code, I can now see the focus being lost on desktops, but still not mobile devices
注意:我通过检查创建旋转器时生成的代码来获取类名。此外,我对 Web 开发非常陌生,所以我不确定是否缺少一种简单的方法。
当单击step up按钮时,输入将获得焦点,因此移动设备显示键盘,解决方案是添加只读属性,当用户单击输入框时,将其删除,在模糊时,重新添加只读属性。
查看代码片段即可理解
$( "#spinner" ).spinner();
$( "#spinner" ).click(function(event){
$(this).removeAttr('readonly').select();
});
$( "#spinner" ).blur(function(event){
$(this).attr('readonly', 'readonly');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<input id="spinner" >
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)