<li><a href="/html/Left-List/SystemLeftList.html" >a setting</a></li>
<li><a href="/html/Left-List/SystemLeftList.html">b Setting</a></li>
<li><a href="/html/Left-List/SystemLeftList.html">c Setting</a></li>
如何寫click a setting 以外的li 都不動作
即點a有動作,b、c無動作
<!DOCTYPE html>
<html lang="en">
<head>
<title>測試</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script
src="https://code.jquery.com/jquery-1.12.4.js"
integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
crossorigin="anonymous">
</script>
</head>
<body>
<ul>
<li class="test"><a href="/html/Left-List/SystemLeftList.html" >a setting</a></li>
<li class="test"><a href="/html/Left-List/SystemLeftList.html">b Setting</a></li>
<li class="test"><a href="/html/Left-List/SystemLeftList.html">c Setting</a></li>
</ul>
</body>
</html>
<script>
$('.test').click(function(){
var index = $(this).index();
var n = $('.test').length;
for (var i = index+1; i < n; i++){
$('.test').eq(i).empty();
}
});
</script>
看不懂你要的動作是什麼,用清空li的內容來代替好了。
增加class在實際上寫網頁會比較實用。
不管你有幾個li,點第n個,n+1以後的都會清空。
<a id="link_a" href="javascript:alink(a);">a setting</a>
<a id="link_b" href="javascript:alink(b);">b setting</a>
<a id="link_c" href="javascript:alink(c);">c setting</a>
function alink(str) {
if (str == a) {
document.getElementId("link_b").remove();
document.getElementId("link_c").remove();
} elseif (str == b) {
document.getElementId("link_c").remove();
} else {
}
}
不知道語法對不對~
但...大概方向如此~給你參考~