开发者

Why is my 'ontouchstart' event not being triggered on iPhone?

开发者 https://www.devze.com 2023-01-08 10:42 出处:网络
This is my code: <div id=\"a\" ontouchstart=\"touchstart(event);\" style=\"width:100px ; height:100px;background:red;\"></div>

This is my code:

<div id="a" ontouchstart="touchstart(event);" style="width:100px ; height:100px;background:red;"></div>
<script src="jquery-1.4.2开发者_StackOverflow社区.js" type="text/javascript"></script>
<script>
    function touchstart(event){
            $('#a').css('width','1000px')
        }
</script>

What's wrong with my code?

Thanks

updated:*

when i add this code, it can be triggered:

$('#a')[0].addEventListener("touchstart", touchstart, false);

So, why is ontouchstart="touchstart(event);" not being triggered?


You need to append the scope to the assignment. Try this

<div id="a" ontouchstart="javascript:touchstart(event);" style="width:100px ; height:100px;background:red;"></div>
0

精彩评论

暂无评论...
验证码 换一张
取 消