2010-07-24 88 views
1

这是我的代码:为什么我的'ontouchstart'事件不会在iPhone上触发?

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

这有什么错我的代码?

感谢

更新:*

当我添加此代码,可以触发:

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

那么,为什么ontouchstart="touchstart(event);"没有被触发?

+2

请问一个问题,请用更好的英语。另外,请更深入地解释你的问题,不要只说“这是我的代码,它不工作,修复它。” – esqew 2010-07-24 02:16:17

+46

我的英语将帮助你学习中文 – zjm1126 2010-07-24 02:23:21

+0

你的代码对我来说在iphone3和iphone4上运行良好吗? – 2010-07-24 03:20:41

回答

4

您需要将作用域附加到作业。试试这个

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