最后添加列表内容?

时间:2010-04-24 09:31:34

标签: php javascript html

其实我的代码是---

function addElement(url,imagePath){
alert(url);

alert(imagePath);

var container = document.getElementById('sncs');


var new_element = document.createElement('li');

new_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' height='165' onClick=\"javascript:addWidget('"+url+"')\"></a>";  
new_element.className="jcarousel-item jcarousel-item-horizontal jcarousel-item-4 jcarousel-item-4-horizontal";
container.insertBefore(new_element, container.firstChild);
}
function addWidget(url) {
   alert(url);
   // var url='http://www.boxyourtvtrial.com/songs/public/';
   var  main= document.getElementById('mainwidget'); 
   main.innerHTML = "<iframe src='"+url+"' align='left' height='1060px' width='576px' scrolling='no'  frameborder='0' id='lodex'></iframe>";
} 

但是当我们添加图像时,它不会发生在前面...... 所以请提供解决方案

1 个答案:

答案 0 :(得分:1)

尝试使用

container.appendChild( new_element );

而不是

container.insertBefore(new_element, container.firstChild)