Gumbo
Erfahrenes Mitglied
Ich habe mal etwas zusammengefummelt:
Ich hoffe, es funktioniert.
HTML:
<script type="text/javascript"><!--
window.onload = init;
function init() {
var list = document.getElementById("foobar");
var items = list.getElementsByTagName("li");
for(var i=0; i<items.length; i++) {
var spanElements = items[i].getElementsByTagName("span");
for(var j=0; j<spanElements.length; j++) {
if( spanElements[j].className.match(/controlls/) ) {
spanElements[j].parentNode.removeChild(spanElements[j]);
}
}
var _spanElement = document.createElement("span");
_spanElement.className = "controlls";
if( i != items.length-1 ) {
var _buttonElement = document.createElement("button");
_buttonElement.innerHTML = "?";
_buttonElement.className = "move-down";
_buttonElement.onclick = new Function("item_moveDown(getParentElement(this, 'li'))");
_spanElement.appendChild(_buttonElement);
}
if( i != 0 ) {
var _buttonElement = document.createElement("button");
_buttonElement.innerHTML = "?";
_buttonElement.className = "move-up";
_buttonElement.onclick = new Function("item_moveUp(getParentElement(this, 'li'))");
_spanElement.appendChild(_buttonElement);
}
items[i].appendChild(_spanElement);
}
}
function getParentElement( obj, tagName )
{
var elem = obj;
while( elem = elem.parentNode ) {
if( elem.nodeName == tagName.toUpperCase() ) {
break;
}
}
return elem;
}
function item_moveUp( obj )
{
getParentElement(obj, "ul").insertBefore(obj, obj.previousSibling);
init();
}
function item_moveDown( obj )
{
getParentElement(obj, "ul").insertBefore(obj, obj.nextSibling.nextSibling);
init();
}
//-->
</script>
<ul id="foobar">
<li>foobar 1<input type="file"></li>
<li>foobar 2<input type="file"></li>
<li>foobar 3<input type="file"></li>
<li>foobar 4<input type="file"></li>
<li>foobar 5<input type="file"></li>
</ul>