日期:2014-05-17  浏览次数:20653 次

一个html页面通过button来增加节点a,在线等
一个html页面有个button
每次点击这个button在页面上新增加一个节点a
但是每次增加的a的href不同  如何实现?thanks

------解决方案--------------------
<script type="text/javascript" language="javascript">
var obj1=new Object();
obj1.name="baidu";
obj1.href="http://www.baidu.com";
var obj2=new Object();
obj2.name="google";
obj2.href="http://www.google.com.hk";
var obj3=new Object();
obj3.name="sina";
obj3.href="http://www.sina.com.cn";


Array.prototype.remove=function(obj){
  for(var i =0;i <this.length;i++){  
var temp = this[i];  
if(!isNaN(obj)){  
temp=i;  
}  
if(temp == obj){  
for(var j = i;j <this.length;j++){  
this[j]=this[j+1];  
}  
this.length = this.length-1;  
}     
}  
}
var arr=new Array();
arr.push(obj1,obj2,obj3);


function add(){

for(var i=0;i<arr.length;){
var s=document.createElement("br");
var a=document.createElement("a");
a.href=arr[i].href;
a.innerText=arr[i].name;
document.body.appendChild(a);
document.body.appendChild(s);
arr.remove(arr[i]);
return;
}
}
</script>




<body>
<input type="button" value="ADD" onclick="add()" /><br />
</body>
------解决方案--------------------
同求...我觉得这就是最简单的了...js读数据库或文件 我不会..只能存在变量里了...
------解决方案--------------------
引用:
3楼的
Array.prototype.remove=function(obj){
  for(var i =0;i <this.length;i++){  
var temp = this[i];  
if(!isNaN(obj)){  
temp=i;  
}  
if(temp == obj){  
for(var j = i;j <this.length;j++){  
this[j]=this[j+1];