jQuery와 함께 극단적 인 놈입니다.jQuery - 동일한 클래스 이름을 사용하여 항목을 개별적으로 표시/숨기기
다른 항목을 표시하지 않고 해당 링크를 기반으로 항목을 표시하려고합니다. 내 모든 링크는 동일한 클래스 이름과 범위를가집니다.
이 작업을 수행 할 수 있는지 여부는 알 수 없습니다. 너무 오랫동안 내 머리를 고생 시켰습니다.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<title>jQuery - Show/Hide items individually with same class name</title>
<style type="text/css">
* { outline: none; }
a { display: inline-block; margin-right: 10px; float: left; text-decoration: none; padding: 10px; }
span { text-align: center; display: inline; padding: 20px; background: blue; color: #fff; float: left; margin-right: 20px; width: 120px; }
div#wrap { float: left; clear: left; margin-top: 10px; }
div#linkOne, div#linkTwo, div#linkThree { background: #ccc; display: inline-block; float: left; margin-right: 20px; }
</style>
<script type="text/javascript">
$(document).ready(function(){
var spans = $("span").each(function(j){ $(this).attr({class : "myDiv" + j}) });
$(spans).hide();
$(".show").each(function(i){
$(this).attr({class : "show" + i});
$(this).bind("click", function(e){
$(spans).show();
});
});
$(".hide").click(function(){
$(spans).hide();
});
});
</script>
</head>
<body>
<div id="linkOne">
<a class="show" href="#">Show1</a>
<a class="hide" href="#">Hide1</a>
</div>
<div id="linkTwo">
<a class="show" href="#">Show2</a>
<a class="hide" href="#">Hide2</a>
</div>
<div id="linkThree">
<a class="show" href="#">Show3</a>
<a class="hide" href="#">Hide3</a>
</div>
<div id="wrap">
<span class="myDiv">div1</span>
<span class="myDiv">div2</span>
<span class="myDiv">div3</span>
</div>
</body>
</html>
아마 VAR 걸쳐 = $ ("스팬"). 각 (함수 (j) {$ (이) .addClass ("myDiv"+ J)}) ; –