gpt4 book ai didi

jquery - .live 工作,但 .on 不工作

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

在我的代码中,当我用 .on 替换 .live 时它不起作用?我无法确定问题所在。

$(document).ready(function () {
/* Reading the data from XML file*/
$.ajax({
type: "GET",
url: "photos.xml",
dataType: "xml",
success: function (xml) {
$(xml).find('item').each(function () {
var path = $(this).attr('path');
var width = $(this).attr('width');
var height = $(this).attr('height');
var id = $(this).attr('id');
var alt = $(this).attr('alt');
var longdesc = $(this).find('longdesc').text();
var description = $(this).find('desc').text();
$('#myImageFlow').append('<img src="' + path + '" id=' + id + ' height="' + height + '" width="' + width + '" longdesc="' + longdesc + '" alt="' + alt + '"/>');
imgArr[i] = description;
imgFront[i] = longdesc;
i = i + 1;
});

$(xml).promise().done(function () {
console.log("image completed loading");
$('img:lt(4)').removeClass('t2').addClass('t1');
$('img:gt(3)').removeClass('t1').addClass('t2');
$('img#id12').removeClass('t1').addClass('t2');
$('img#id1').removeClass();


//alert('Front Initial Text is'+imgFront[1]);
window.setTimeout(function () {

$("#front").html(imgFront[1]);
$("#front").css("background", "gray");
}, 1500);
});
}
});
$.getScript('js/code.photoswipe.jquery-3.0.5.js');
});

/*front div called when front or back is called */
$('#front').live('click', function (event) {
event.stopPropagation();
transitIt(this);
// alert('Front Clicked glob e='+globe);
});


$('#myImageFlow img').on("click", function () {
event.stopPropagation();
alert('htmlcalled image Clicked Called=' + clickEnabled);
});

最佳答案

您的委托(delegate)可能未正确定义:

$('#myImageFlow').on("click", 'img', function(event) {
event.stopPropagation();
alert('htmlcalled image Clicked Called=' + clickEnabled);
});

假设 #myImageFlow 没有从 DOM 中删除,它是事件委托(delegate)的一个很好的候选者。此外,您在点击处理程序中缺少 event 参数。

关于jquery - .live 工作,但 .on 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16769555/

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