gpt4 book ai didi

javascript - Jquery .live 事件没有触发

转载 作者:行者123 更新时间:2023-11-29 16:16:32 24 4
gpt4 key购买 nike

我有一个关于 .live 触摸事件的简单问题。我想要做的是当用户点击/触摸页面主体(容器)时,调用 refreshCanvas 函数。但是,这似乎对我不起作用。

JavaScript:

<script type="text/javascript">
function refreshCanvas () {
var code = document.getElementById('iframe');
code.src = code.src; // that is the essence here
}
setInterval(refreshIframe1, 20000);
function refreshIframe1() {
$("#iframe")[0].src = $("#iframe")[0].src;
}
$('#container').live("tap", function() {
refreshCanvas();
});
</script>

HTML:

  <a href="javascript:refreshCanvas()"><img src="data/refresh.jpg"></a>
<div id="container">
<iframe id="iframe" src="data/canvas.html" z-index: 0; style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%"></iframe>
</div>

最佳答案

如果您使用的是最新版本的 jQuery (1.9),they have removed the .live() method of binding events entirely并推荐您使用/学习 .on()方法。

$('.something').live('event', function(){...});

相当于

$(document).on('event', '.something', function(){...});

关于javascript - Jquery .live 事件没有触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14635812/

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