为什么我的“ontouchstart”是iPhone 上未触发事件?

发布于 2024-09-11 08:50:28 字数 588 浏览 1 评论 0原文

这是我的代码:

<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);" 没有被触发?

This is my code:

<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>

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光礼记 2024-09-18 08:50:28

您需要将范围附加到作业中。试试这个

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文