单击iframe中的类以执行父jquery
谢谢你读到这个 我在主页上有一个class=test1,主页动态创建了iframe,然后有class=test1的元素。目的是每当test1点击时,执行一个代码…比如alerthey 下面的代码添加iframe单击iframe中的类以执行父jquery,jquery,dialog,Jquery,Dialog,谢谢你读到这个 我在主页上有一个class=test1,主页动态创建了iframe,然后有class=test1的元素。目的是每当test1点击时,执行一个代码…比如alerthey 下面的代码添加iframe $(document).ready(function() { $("body").on("click",".add_movie_button", function (event) { event.preventDefault(); iframe
$(document).ready(function() {
$("body").on("click",".add_movie_button", function (event) {
event.preventDefault();
iframe = $('<iframe id="iframe_add_movie" frameborder="0" height="100%" width="100%" scrolling="no"></iframe>');
var search_string = $("#search").val();
$('#add_movie_dialog').append(iframe).dialog({
autoOpen: true,
dialogClass: "no-title",
resizable:false,
modal:true,
position: 'center',
height: 600,
width:400,
open: function (event, ui) {
$('#iframe_add_movie').attr('src','addmovie.php?search_string='+search_string);
$(this).css('overflow', 'hidden'); //this line does the actual hiding
}
});
//click outside to close
$(".ui-widget-overlay").on("click", function() {
$("#add_movie_dialog").dialog( "close" );
});
});
需要有关如何在iframe中单击class=test1并在父级中打开alerthay的帮助吗
iframe = $('<iframe id="iframe_add_movie" frameborder="0" height="100%" width="100%" scrolling="no"></iframe>').load(function(){
$(this).contents().find('p').click(function(){
alert('bar');
});
});
这需要在创建iFrame iFrame\u add\u电影之后,以及在加载页面之后,即.load处理程序之后进行
请注意,如果iframe源指向另一个域,您将无法访问内容,因为。只是发布,因为这对我很有用……希望未来的读者能从中受益 下面是一个对话框 这是jquery使用的 `$document.readyfunction{ $body.onclick、.add_movie_按钮、函数事件{ 违约事件
var search_string = $("#search").val();
$('#add_movie_dialog').dialog({
autoOpen: false,
dialogClass: "no-title",
resizable:false,
height:600,
width: 400,
modal:true,
position: 'center',
open: function (event, ui) {
$('#iframe_add_movie').attr('src','addmovie.php?search_string='+search_string);
$(this).css('overflow', 'hidden');
$('#iframe_add_movie').load(function() {
var $content = $("#iframe_add_movie").contents();
$content.find("body").on( "click", ".search_movie", function() {
event.preventDefault();
var clickedID = this.id.split("-");
var m_id = clickedID[1]; //and get number from array
// Use transfer effect
$(this).effect("transfer", { to: $("#load_area") }, 1000);
load_movie(m_id); ///some function to do stuff
});
});
},
});
$('#add_movie_dialog').dialog("open");
//click outside to close
$(".ui-widget-overlay").on("click", function() {
$("#add_movie_dialog").dialog( "close" );
});
});
}“警报是阻止事件。当警报处于活动状态时,无论是帧还是非帧,您都无法执行任何操作。或者,我错误地解释了您的问题,因为语言很难理解。警报是阻止事件--请解释。我使用警报检查代码是否正常。抱歉,朋友,它不正常,我尝试了此操作,但仍然无效。$”如果rame_add_movie'.contents.find'.test1'。单击函数{alerthello;};@user3525233我已更新了我的答案。由于同源策略,我无法修改,但这在我进行本地测试时有效!在将页面加载到iframe中后,您必须进行绑定。谢谢dave,您的答案为我提供了工作线索。但是,您能否帮助将对话框的高度更改为iframe的高度?不客气。您正在指定iframe中的高度上面的代码。height:600,在对话框调用中,iframe元素的height=100%。您试图实现什么?height:600,--表示对话框,height=100%表示iframe到整个空间。我正在考虑下一步获取iframe的高度,然后在对话框height中声明…但无法实现它…猜猜看