Why is my 'ontouchstart' event not being triggered on iPhone?
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>
精彩评论