最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why can't I click input? - Stack Overflow

programmeradmin4浏览0评论

I'm using iScroll4 plugin (/) to add scrollbar to pages that are longer than 80% of height of the browser's viewport. For some reason when (and only in this case) I add it and try to click on input, it won't select. Only clicking on its label will select input.

What can I do to have iScroll4 and selectable input?

I'm using iScroll4 plugin (http://cubiq/iscroll-4/) to add scrollbar to pages that are longer than 80% of height of the browser's viewport. For some reason when (and only in this case) I add it and try to click on input, it won't select. Only clicking on its label will select input.

What can I do to have iScroll4 and selectable input?

Share Improve this question edited Dec 24, 2016 at 19:37 darryn.ten 6,9833 gold badges50 silver badges66 bronze badges asked Feb 9, 2012 at 11:38 AtadjAtadj 7,18020 gold badges72 silver badges94 bronze badges 3
  • 1 Oddly enough right-clicking the input elements will move the focus to that element (even if you dismiss the context menu), but not clicking. – David Thomas Commented Feb 9, 2012 at 11:41
  • Yes, it works on right-click and label-click but not left-click also for me :) – Atadj Commented Feb 9, 2012 at 11:44
  • It might have something to do with your markup. You shouldn't nest an input inside a label tag. Is the markup dynamic? Maybe you should look into cutting down on the number of nested tags. – Alex Morales Commented Feb 9, 2012 at 13:46
Add a ment  | 

4 Answers 4

Reset to default 12

Try this solution

   myScroll = new iScroll('wrapper', {});

   myScroll.options.onBeforeScrollStart = function(e) {                
        var target = e.target;

        while (target.nodeType != 1) target = target.parentNode;
        if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA'){
            e.preventDefault();
        }
   }
$('input[type=text]').bind('touchstart click', function(){
    $(this).focus();
});
var myScroll;
function loaded() {
    myScroll = new iScroll('wrapper', { scrollbarClass: 'myScrollbar' });

   myScroll.options.onBeforeScrollStart = function(e) {                
        var target = e.target;

        while (target.nodeType != 1) target = target.parentNode;
        if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA'){
            e.preventDefault();
        }
    }
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

document.addEventListener('DOMContentLoaded', loaded, false);

I use version 5.1.2 and it worked.

 window.myScroll = new IScroll ('#iscroll-wrapper',
    probeType:  3,
    mouseWheel: true,
    scrollbars: true,
    bounce: true,
    keyBindings: true,
    invertWheelDirection: false,
    momentum: true,
    fadeScrollbars: false,
    interactiveScrollbars: true,
    resizeScrollbars: true,
    shrinkScrollbars: false,
    click: false,
    preventDefaultException: { tagName:/.*/ }
}
发布评论

评论列表(0)

  1. 暂无评论