将一个div的innerHTML分配给另一个div,而不是立即反映 [英] Assigning innerHTML of one div to another div, not reflecting immediately

查看:103
本文介绍了将一个div的innerHTML分配给另一个div,而不是立即反映的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我将div的innerHTML分配给另一个div,问题是当我显示我已分配给我的第二个div时,不会反映分配的innerHTML firefox中第一个div的innerHTML,但它在其他浏览器中工作正常。


我也观察到,指定的第二个div的innerHTML会在一段时间后反映出来。为什么它会在一段时间后反映出来。

解决方案

欢迎来到TheScripts。


请发布您的代码。

啊! firefox在使用innerHTML属性时多次出现问题。

所以我相信为此目的操纵DOM,它总是可靠的。


我也使用innerHTML属性,但每当涉及到纯文本时,我依靠操纵DOM。


我建议你也一样。这是我个人的经历,但并不完全依赖我,因为我不是专家,等待专家的建议。


这里是代码


首先我有两个div i)外部Div即''DivCartLayer''ii)内部Div''divCartContents''。


var strHTMLOutput ="< Html将动态生成>"


1)新形成的html将分配给内部Div,如下所示

文件。 getElementById(''divCartContents'')。innerHT ML = strHTMLOutput;


这里使用''testDIV''一个新的div,用于滑动图层(购物车数据)。

为此,我使用


document.getElementById(''testDIV'')。innerHTML = docum ent.getElementById(''DivCartLayer' ').innerHTML;


一旦我将外部div的innerHTML分配给新div,我使用以下函数来滑动新div。

/>
< script language =" JavaScript1.2">

maxTopPx = -160;

maxBottomPx = 150;


themenu = document.all.testDIV.style

函数pull()

{

if( window.drawit)

clearInterval(drawit)


pullit = setInterval(" pullengine()",10)

}


函数pullengine()

{

if(parseInt(themenu.top)< maxBottomPx)

themenu.top = parseInt(themenu.top)+ 10 +" px"

else // if(window.pullit)

$

clearInterval(pullit)

// clearInterval(cartLayerId)

document.getElementById(''divCartContents'')。style。 o verflow =''auto'';

}

}


函数抽奖()

{

document.getElementById(''divCartContents'')。style.o verflow =" hidden";


clearInterval(pullit)


drawit = setInterval(" drawengine()",5)

}


函数drawengine()

{

if(parseInt(themenu.top)> maxTopPx)

themenu.top = parseInt(themenu.top)-10 +" px"

else // if(window.drawit)

{

clearInterval(drawit)

themenu。 top = maxTopPx

}

}

< / script>



这里有2个问题。


1)将外部div的HTML分配给新divtestDIV后,当这个div向下滑动时我无法看到最新生成的html.it总是显示旧的HTML。


2)如果我在firefox中的任何其他div下滚动一个div,它的闪烁(在FF和netscape),但在IE6,IE7,Safari中工作正常。因此我在滚动时隐藏滚动,滚动完成后滚动可见。

然后它也无法在ff和netscape中工作。


Hi,

Am assigning the innerHTML of a div to another div, the problem is that the assigned innerHTML is not reflected when i display the second div to which i have assigned the innerHTML of the first div in firefox, but it works fine in othe browsers.

I also observed that, the assigned innerHTML to the second div is reflecting after some time. Why''s it reflecting after some time.

解决方案

Welcome to TheScripts.

Please post your code.


yea! firefox creates problems many times while using innerHTML property.
So I believe in manipulating DOM for that purpose, it is always reliable.

I also use the innerHTML property, but whenever there is plain text involved, then I rely on manipulate DOM.

I suggest you the same. It''s my personal experience, but don''t fully rely on me, as I am not an expert, wait for expert''s advices.


Here''s the code

Firstly i have two divs i) Outer Div namely ''DivCartLayer'' ii) inner Div ''divCartContents''.

var strHTMLOutput="<Html will be generated dynamically>"

1) The newly formed html will be assigned to inner Div as follows
document.getElementById(''divCartContents'').innerHT ML=strHTMLOutput;


Here am using ''testDIV'' a new div, which i use for sliding the layer(cart data).
For this i use

document.getElementById(''testDIV'').innerHTML=docum ent.getElementById(''DivCartLayer'').innerHTML;


Once i assign the outer div''s innerHTML to the new div, i use the following functions to slide the new div.


<script language="JavaScript1.2">
maxTopPx = -160;
maxBottomPx = 150;

themenu = document.all.testDIV.style

function pull()
{
if (window.drawit)
clearInterval(drawit)

pullit = setInterval("pullengine()",10)
}

function pullengine()
{
if (parseInt(themenu.top) < maxBottomPx)
themenu.top=parseInt(themenu.top)+10+"px"
else //if (window.pullit)
{
clearInterval(pullit)
//clearInterval(cartLayerId)
document.getElementById(''divCartContents'').style.o verflow = ''auto'';
}
}

function draw()
{
document.getElementById(''divCartContents'').style.o verflow = "hidden";

clearInterval(pullit)

drawit = setInterval("drawengine()", 5)
}

function drawengine()
{
if (parseInt(themenu.top)>maxTopPx)
themenu.top = parseInt(themenu.top)-10+"px"
else //if (window.drawit)
{
clearInterval(drawit)
themenu.top=maxTopPx
}
}
</script>


Here am getting 2 problems.

1) After assigning the outer div''s HTML to the new div ''testDIV'', when this div slides down i am not able to see the latest generated html.it always shows the old html.

2) If i scroll a div under any other div''s in firefox , its flickering(on FF and netscape),but working fine in IE6,IE7,Safari. So i hided the scroll when its scrolling and once the scrolling is complete i made the scroll visible.
Then also its not working in ff and netscape.


这篇关于将一个div的innerHTML分配给另一个div,而不是立即反映的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆