C# 如何在colorbox onload方法中设置图像单击事件
我正在使用带有iframe的colorbox插件。iframe源代码是另一个HTML页面,它有一个图像库。在这里,我需要编写一个单击事件来获取单击图像的id document ready中HTML页面上的普通单击事件不起作用,我也尝试了live。我还尝试在colorbox onload函数中设置一个click事件,但失败了 它是一个使用asp.NET4.0的Web应用程序 请帮我写一个点击事件 我调用颜色框的脚本C# 如何在colorbox onload方法中设置图像单击事件,c#,jquery,C#,Jquery,我正在使用带有iframe的colorbox插件。iframe源代码是另一个HTML页面,它有一个图像库。在这里,我需要编写一个单击事件来获取单击图像的id document ready中HTML页面上的普通单击事件不起作用,我也尝试了live。我还尝试在colorbox onload函数中设置一个click事件,但失败了 它是一个使用asp.NET4.0的Web应用程序 请帮我写一个点击事件 我调用颜色框的脚本 $(".iframe").colorbox({ iframe: true, wid
$(".iframe").colorbox({ iframe: true, width: "70%", height: "80%" });
$(".iframe").colorbox({
onLoad: function () {
alert('onLoad: colorbox has started to load the targeted content');
$('ul#boutiquegallery img').on('click', function () {
alert('clciked img');
});
},
onComplete: function () {
alert('onComplete: colorbox has displayed the loaded content');
},
//onClosed: function () { alert('onClosed: colorbox has completely closed'); }
});
我在HTML中尝试的脚本
(function ($) {
$('#boutique').boutique();
//$("iframe.cboxIframe").contents().find($('ul#boutique img').live('click', function () {
// var id = $(this).attr('id');
// alert(id);
//}));
//$("iframe.cboxIframe").load(function () {
// alert('hi');
// // write your code here
// $('a').click(function () {
// alert('clciked');
// });
// $('img').live('click', function () {
// alert('clciked img');
// });
//});
})(jQuery);
$(document).ready(function () {
//$('img').on('click', function () {
// alert('clciked img');
//});
//$('iframe.cboxIframe').load(function () {
// $('iframe.cboxIframe').contents().find('img').live({
// click: function () {
// alert('clicked img');
// }
// });
//});
});
尝试此额外步骤:
var iFrameDoc = $(".iframe").contentDocument || $(".iframe").contentWindow.document;
iFrameDoc.colorbox({
// rest of the code is the same as yours after here
onLoad: function () {
alert('onLoad: colorbox has started to load the targeted content');
$('ul#boutiquegallery img').on('click', function () {
alert('clciked img');
});
},
onComplete: function () {
alert('onComplete: colorbox has displayed the loaded content');
},
//onClosed: function () { alert('onClosed: colorbox has completely closed'); }
});
当尝试访问DOM对象时,iFrame可能会很棘手:我的HTML页面中的以下代码已经完成了这一任务
$(document).on('click', 'img', function () {
alert('hi dsad');
alert($(this).attr('src'));
});
谢谢你的回复,坎南。我在这里发布我的代码。代码伙计,你也可以把它放在像JSFIDLE一样的地方,与我们共享链接,我们可以调整它并帮助你。对不起,亲爱的,我是新来的。我刚刚用代码更新了帖子。请看一看,嗨,我使用了你上面给出的相同代码,它不起作用。在我的HTML页面上还有其他方法吗?。在我之前发布的代码中,onload警报起作用,而单击事件不起作用。感谢kannan为您提供宝贵的时间。我找到了解决办法。