function creatIframe(href,titleName){
var topWindow=$(window.parent.document);
var show_nav=topWindow.find('#min_title_list');
show_nav.find('li').removeClass("active");
var iframe_box=topWindow.find('#iframe_box');
show_nav.append(''+titleName+' ');
var taballwidth=0,
$tabNav = topWindow.find(".acrossTab"),
$tabNavWp = topWindow.find(".Hui-tabNav-wp"),
$tabNavitem = topWindow.find(".acrossTab li"),
$tabNavmore =topWindow.find(".Hui-tabNav-more");
if (!$tabNav[0]){return}
$tabNavitem.each(function(index, element) {
taballwidth+=Number(parseFloat($(this).width()+60))
});
$tabNav.width(taballwidth+25);
var w = $tabNavWp.width();
if(taballwidth+25>w){
$tabNavmore.show()}
else{
$tabNavmore.hide();
$tabNav.css({left:0})
}
var iframeBox=iframe_box.find('.show_iframe');
iframeBox.hide();
// iframe_box.append('');
// var newCreatifm = iframe_box.append('');
var framebox = $('');
var newCreatifm = framebox.appendTo(iframe_box);
// console.log(framebox.find("iframe"));
// console.log(newCreatifm);
var newOneFbox = framebox.find("iframe");
console.log(newOneFbox);
return framebox;
}
我想只返回framebox这个元素到领一个方法中,但是调用另一个方法这个元素还是创建了一个新的,如果只是获取这framebox dom节点应该怎么做?
测试代码: function a(){ creatIframe(); } a();//获取到framebox节点的同时,又创建了这个节点。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
调用createIframe每次都会创建一个新的,因为你把
var framebox = $('<p class="show_iframe"><iframe scrolling="no" border="0" frameborder="0" marginwidth="0" marginheight="0" onload="this.style.height=Math.max(this.contentWindow.document.body.scrollHeight,this.contentWindow.document.documentElement.scrollHeight,200)+'px'" src='+href+' ></iframe></p>');写在了方法里面,每次调用都会执行这个语句。把这个创建framebox 写在函数之外,每次调用直接使用就不会生成新的了。