我的标题中有这些行
$( document ).ready(function() {
$(".thumb").hide();
$(".thumb").first().show();
$(".text" ).mouseenter(function() {
$(this).prev(".thumb").show();
}).mouseleave(function() {
$(this).prev(".thumb").hide();
});
});
它们在页面加载时工作正常,但一旦我使用 AJAX 加载新的 HTML 内容,这些行就会被忽略。
在我之前的问题中,一些温和的人告诉我使用 .on() 好的。但是我如何将这个 .on() 应用于上面的代码?
我知道这对你们大多数人来说都是一个愚蠢的问题,但我是一个绝对的初学者, 如果有人能提供一些有用的建议,我将非常感激。
最佳答案
你的代码将是这样的(可以修改)
$(document).ready(function() {
$(".thumb").hide();
$(".thumb").first().show();
$(document).on('mouseenter',".text",function(){ $(this).prev(".thumb").show(); })
$(document).on('mouseleave',".text",function(){ $(this).prev(".thumb").hide(); })
});
关于javascript - .on() 和 AJAX 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26745473/