3
如何排序列表而不實現if裏面的iframe? (appendChild使iframe重新加載)排序列表無需重新加載iframe
<script>
window.onload = function() {
var my_ul = document.getElementById('my_ul'),
my_button = document.getElementById('my_button');
function sort_function() {
for(var i = 0; i < 5; i++) {
var list = [1, 2, 3, 4, 5];
my_ul.appendChild(document.querySelector('[data-sort="' + list[i] + '"]'));
}
}
my_button.onclick = function() {
sort_function();
}
}
</script>
<a id=my_button href="#">Sort</a>
<ul id=my_ul>
<li data-sort=3>3<iframe src="#3"></iframe>
<li data-sort=2>2<iframe src="#2"></iframe>
<li data-sort=4>4<iframe src="#4"></iframe>
<li data-sort=1>1<iframe src="#1"></iframe>
<li data-sort=5>5<iframe src="#5"></iframe>
</ul>
選中此http://stackoverflow.com/questions/7434230/how-to-prevent-an-iframe-from-reloading-when-moving-it-in-the -dom – 2013-05-02 08:53:01