【问题标题】:Where are ontouch() events allow to be? Why not on DIV's?ontouch() 事件允许在哪里?为什么不在DIV上?
【发布时间】:2014-11-11 06:07:24
【问题描述】:

validator.w3.org 正在抛出错误:

此时元素 div 上不允许使用 ontouchmove 属性。

关于以下代码:

<div id="someDiv" ontouchmove="onTouchmove(event)" ontouchend="noTouch(event)"></div>

文档类型是:

<!DOCTYPE HTML>

哪些元素上允许触摸事件?

【问题讨论】:

    标签: html touch w3c-validation


    【解决方案1】:

    远离 dom

    使用 jQuery,它看起来像:

    $('#someDiv').live('ontouchmove',function(e){
        onTouchmove(e);
    });
    
    $('#someDiv').live('ontouchend',function(e){
        noTouch(e);
    });
    

    【讨论】:

    • 我的页面运行方式似乎更有意义,因为它位于标签中(onclick 等从未给我带来任何问题)。这就像一个魅力。把它放在$(document).ready(function(){}); 中,瞧——有效!
    • 感觉不是很好吗? :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2019-01-23
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多