移動端使用isscroll.js input沒法獲取焦點(就是點了沒反應啦!)

有幸網上找到了解決的辦法html

只要在代碼里加入如下一段代碼就能夠了spa

function allowFormsInIscroll(){
 [].slice.call(document.querySelectorAll('input, select, button')).forEach(function(el){
 el.addEventListener(('ontouchstart' in window)?'touchstart':'mousedown', function(e){
 e.stopPropagation();
 
 })
 })
 }
 document.addEventListener('DOMContentLoaded', allowFormsInIscroll, false);

 問題緣由是:iscroll須要一直監聽用戶的touch操做,以便靈敏的作出對應效果,因此它把其他的默認事件屏蔽了。code

以上代碼原理是:頁面加載完成後查找到全部的'input, select, button'元素並依次綁定'touchstart'或'mousedown'事件,在執行事件的時候中止事件的傳播,這樣行了。orm

原做者地址:http://www.cnblogs.com/duanhuajian/archive/2012/11/09/2763159.htmlhtm

相關文章
相關標籤/搜索