touchend事件的preventDefault阻止掉了click事件

<div id="box">box</div>

<script>

    var isTouchDevice = function() {

        return 'ontouchstart' in window

    }()

    var startEvt = isTouchDevice ? 'touchstart' : 'mousedown'

    var moveEvt  = isTouchDevice ? 'touchmove' : 'mousemove'

    var endEvt   = isTouchDevice ? 'touchend' : 'mouseup'

    var box = document.querySelector('#box')



    function add(type) {

        var div = document.createElement('div')

        div.innerHTML = type

        box.appendChild(div)

    }

    box.addEventListener(startEvt, function(event) {

        add(startEvt)

    })

    box.addEventListener(moveEvt, function(event) {

        add(moveEvt)

    })

    box.addEventListener(endEvt, function(event) {

        //event.preventDefault()

        add(endEvt)

    })

    box.addEventListener('click', function(event) {

        add('click')

    })

</script>

 

document.body的click事件无效

document.documentElement的click事件ok

你可能感兴趣的:(event)