gpt4 book ai didi

jquery 单击阻止转到页面顶部

转载 作者:行者123 更新时间:2023-12-01 06:49:35 25 4
gpt4 key购买 nike

我的页面上有许多图像。有些位于页面底部,需要滚动。我发现,当我点击图像时,图像会变成视频,它会让我转到页面顶部。

这是我的代码:

$('#videoconner').click(function () {
$(this).replaceWith('<iframe width="280" height="164" src="http://www.youtube.com/embed/6kR2n4344UCAU?autoplay=1&cc_load_policy=1&rel=0" frameborder="0" allowfullscreen></iframe>');
});

我添加:

e.preventDefault();

但这并没有帮助。

有什么办法可以防止转到页面顶部吗?

最佳答案

e(事件参数)添加到您的点击函数中。

$('#videoconner').click(function (e) {
e.preventDefault();
$(this).replaceWith('<iframe width="280" height="164" src="http://www.youtube.com/embed/6kR2n4344UCAU?autoplay=1&cc_load_policy=1&rel=0" frameborder="0" allowfullscreen></iframe>');
});

关于jquery 单击阻止转到页面顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17116192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com