如何使這一個li元素將是第一個,因爲用戶在下一頁單擊(www.url.com/demo/#collapse1) - 應該是第一個或(www.url.com/demo/#collapse5) - 是第一個嗎?當你在同一頁面時,其他元素將留在他們的位置。 www.url.com/demo只有一個列表元素首先在頁面加載
$('li').click(function() {
$(this).prependTo($(this).parent());
});
body {
font-family: verdana;
font-size: 12px;
}
a {
text-decoration: none;
color: #000;
display: block;
width: 100%;
padding: 8px 0;
text-indent: 10px;
}
a:hover {
text-decoration: underline;
}
ul {
list-style: none;
}
ul li {
background: #eee;
margin-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><a href="#one">01</a></li>
<li><a href="#two">02</a></li>
<li><a href="#three">03</a></li>
<li><a href="#four">04</a></li>
<li><a href="#">05</a></li>
</ul>
不清楚自己想要達到的目標,你能解釋一下多一點 –
例如:你在Facebook和看到www.url.com /#東西鏈接。 你點擊了它。該元素是頁面上的最後一個,但他首先是因爲你點擊了該鏈接,但其他人ements留在他們的地方。 – Mantas
所以在你的例子中,如果我點擊'3',它就會上升(現在訂單是'3 - 1 - 2 - 4 - 5'),然後如果你點擊4,那麼訂單就是('4-3 - 1 - 2 - 5'),但你真的想要:'(4 - 1 - 2 - 3 - 5)'? –