如果在一个已有的DIV中创建新的DIV
function AddToCompareBasket(imgURL,productURL){
obj = document.createElement( "DIV ");
obj.className= "contrast ";
obj.innerText=productURL;
document.getElementById( "divCompare ").appendChild(obj);
}
这样不可以,不知道如何修改
------解决方案--------------------var obj=document.getElementById( "原来的div的id ")
document.getElementById( "divCompare ").appendChild(obj.cloneNode(true));
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
</head>
<body>
<div id= 'divCompare '> </div>
<input type= "button " onclick= "alert(document.body.innerHTML); " value= "click ">
</body>
</html>
<script language= "JavaScript ">
<!--
function AddToCompareBasket(imgURL,productURL){
obj = document.createElement( "DIV ");
obj.className= "contrast ";
obj.innerText= "ctURL ";
document.getElementById( "divCompare ").appendChild(obj);
}
AddToCompareBasket();
//-->
</script>
你说怎么会不行呢,
真的不行话
appendChild改成
insertAdjacentHTML
的用法
http://blog.csdn.net/rjzou2006/archive/2007/04/30/1593483.aspx
------解决方案--------------------var node = document.createElement( "DIV ");
node.innerHTML = strText;
var myNode = document.getElementById( "a1 ");
myNode.appendChild(node);
------解决方案--------------------insertBefore