获取Ipad touchstart坐标

Mas*_*son 6 javascript web-applications touch coordinates ipad

我想在javascript中获取ipad上触摸事件的坐标.我该怎么做?

sim*_*aun 6

我相信这应该做的伎俩:

var x = event.targetTouches[0].pageX,
    y = event.targetTouches[0].pageY;
Run Code Online (Sandbox Code Playgroud)


更新:
这是一个例子:

<!doctype html>
<html lang="en" class="no-js">
<head>
    <meta charset="utf-8">

    <title>Touch event test</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>

<body>

<script>
    $(function() {
        var $log = $("#log");

        function updateLog(x, y) {
            $log.html('X: '+x+'; Y: '+y);
        }

        document.addEventListener('touchstart', function(e) {
            updateLog(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
        }, false);

        document.addEventListener('touchmove', function(e) {
            e.preventDefault();
            updateLog(e.targetTouches[0].pageX, e.targetTouches[0].pageY);
        }, false);
    });
</script>

<div id="log"></div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)