此功能组织列表,不按字母顺序组织:在Firefox和Internet Explorer中升序/降序。 谷歌Chrome和Edge正在运作。
这是代码:
<fieldset class="inputAdd inline">
答案 0 :(得分:0)
似乎是对的。你的元素ID是对的吗?检查是否还有一个使用相同ID的元素。如果可以,请发布HTML代码。
答案 1 :(得分:0)
试试这个:
document.getElementById("hello").onclick = talk;
function talk()
{
alert('It works!');
}
&#13;
<a id="hello">Click me!</a>
&#13;
答案 2 :(得分:0)
如果您使用未知来源的代码,那么您甚至可能会遇到版权问题!这是一个简化版本(不,我为使用冒泡排序而道歉!)应该很容易理解。
根据OP的要求编辑以添加深度复制的示例
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
// as shown in http://stackoverflow.com/questions/3066427/copy-all-childnodes-to-an-other-element-in-javascript-native-way
function copyElements (dst,src){
while (src.hasChildNodes()) {
dst.appendChild(src.removeChild(src.firstChild))
}
}
function sortUnorderedList(element_id, direction){
var table = document.getElementById(element_id);
var rows,i,tmp;
// get the rows in the order as they are
rows = table.rows;
i = rows.length - 1;
// tmp must be a node for this highly simplified stuff to work
tmp = document.createElement("getoffmylawn");
// do a simple Bubble sort (sorts lexically, maybe not what you want!)
// Assumes things to sort are in the first cell, adjust if necessary
for(; i > 0; i--){
for(j = 0;j < i; j++){
if(direction === false){
if(rows[j].firstChild.firstChild.textContent < rows[j+1].firstChild.firstChild.textContent){
copyElements (tmp , rows[j]);
copyElements (rows[j] , rows[j+1]);
copyElements (rows[j+1] , tmp);
}
}
else{
if(rows[j].firstChild.firstChild.textContent > rows[j+1].firstChild.firstChild.textContent){
copyElements ( tmp , rows[j]);
copyElements (rows[j] , rows[j+1]);
copyElements (rows[j+1] , tmp);
}
}
}
}
}
window.onload = function () {
var desc = false;
document.getElementById("Order").onclick = function () {
sortUnorderedList("FileList", desc);
desc = !desc;
return false;
};
};
</script>
</head>
<body>
<table id="FileList">
<tr><td><a href="a">Foo</a></td></tr>
<tr><td><a href="b">Bar</a></td></tr>
<tr><td><a href="c">Foobar</a></td></tr>
<tr><td><a href="d">Something</a></td></tr>
<tr><td><a href="e">Anything</a></td></tr>
<tr><td><a href="f">Somehwere</a></td></tr>
<tr><td><a href="g">elsewhere</a></td></tr>
<tr><td><a href="h">completely lost</a></td></tr>
</table>
<button id="Order">Sort</button>
</body>
</html>
如果您认为订单有误,您就会发现&#34;词汇顺序&#34;实际上意味着。
答案 3 :(得分:0)
要在Internet Explorer和Firefox中工作,我更换了:
innerText
至textContent