当我复制其容器时,如何让最新更新的表单项在Firefox中“粘贴”?

时间:2022-12-23 02:07:59

I have a dl containing some input boxes that I "clone" with a bit of JavaScript like:

我有一个dl包含一些输入框,我用一些JavaScript“克隆”,如:

var newBox = document.createElement('dl'); 
var sourceBox = document.getElementById(oldkey); 
newBox.innerHTML = sourceBox.innerHTML; 
newBox.id = newkey;          
document.getElementById('boxes').appendChild(columnBox);   

In IE, the form in sourceBox is duplicated in newBox, complete with user-supplied values. In Firefox, last value entered in the orginal sourceBox is not present in newBox. How do I make this "stick?"

在IE中,sourceBox中的表单在newBox中重复,并带有用户提供的值。在Firefox中,在原始sourceBox中输入的最后一个值在newBox中不存在。我怎么做这个“坚持?”

3 个解决方案

#1


0  

Firefox vs. IE: innerHTML handling ?

Firefox与IE:innerHTML处理?

#2


1  

You could try the cloneNode method. It might do a better job of copying the contents. It should also be faster in most cases

您可以尝试cloneNode方法。它可以更好地复制内容。在大多数情况下它也应该更快

var newBox;
var sourceBox = document.getElementById(oldkey);
if (sourceBox.cloneNode) 
    newBox = sourceBox.cloneNode(true);
else {
    newBox = document.createElement(sourceBox.tagName); 
    newBox.innerHTML = sourceBox.innerHTML; 
}
newBox.id = newkey;              
document.getElementById('boxes').appendChild(newBox);

#3


1  

Thanks folks.

I got things to work by using prototype and changing document.getElementById(oldkey) to $(oldkey)

我通过使用原型和将document.getElementById(oldkey)更改为$(oldkey)来完成工作。

<script src="j/prototype.js" type="text/javascript"></script>  

var newBox;  
var sourceBox = $(oldkey);  
if (sourceBox.cloneNode)  
     newBox = sourceBox.cloneNode(true);  
else {  
    newBox = document.createElement(sourceBox.tagName);  
    newBox.innerHTML = sourceBox.innerHTML;  
}  
newBox.id = newkey;  
document.getElementById('boxes').appendChild(newBox);

#1


0  

Firefox vs. IE: innerHTML handling ?

Firefox与IE:innerHTML处理?

#2


1  

You could try the cloneNode method. It might do a better job of copying the contents. It should also be faster in most cases

您可以尝试cloneNode方法。它可以更好地复制内容。在大多数情况下它也应该更快

var newBox;
var sourceBox = document.getElementById(oldkey);
if (sourceBox.cloneNode) 
    newBox = sourceBox.cloneNode(true);
else {
    newBox = document.createElement(sourceBox.tagName); 
    newBox.innerHTML = sourceBox.innerHTML; 
}
newBox.id = newkey;              
document.getElementById('boxes').appendChild(newBox);

#3


1  

Thanks folks.

I got things to work by using prototype and changing document.getElementById(oldkey) to $(oldkey)

我通过使用原型和将document.getElementById(oldkey)更改为$(oldkey)来完成工作。

<script src="j/prototype.js" type="text/javascript"></script>  

var newBox;  
var sourceBox = $(oldkey);  
if (sourceBox.cloneNode)  
     newBox = sourceBox.cloneNode(true);  
else {  
    newBox = document.createElement(sourceBox.tagName);  
    newBox.innerHTML = sourceBox.innerHTML;  
}  
newBox.id = newkey;  
document.getElementById('boxes').appendChild(newBox);