<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var $category = $("ul li:gt(5):not(:last)");
$category.hide();
$("input").click(function(){
if($category.is(":visiable")){
$category.hide();
$("input").attr("value","精简显示")
}
else{
$category.show();
$("input").attr("value","全部显示")
}
})
});
</script>
</head>
<body>
<div class="category">
<ul>
<li>苹果</li>
<li>诺基亚</li>
<li>摩托罗拉</li>
<li>索爱</li>
<li>三星</li>
<li>LG</li>
<li>黑莓</li>
<li>多普达</li>
<li>西门子</li>
<li>魅族</li>
<li>其他品牌</li>
</ul>
</div>
<div class="more"><input type="button" value="全部显示"></div>
代码错误,但我不知道有什么问题,你能帮助我吗?
答案 0 :(得分:1)
可能是$category.is(":visiable")
拼错了(应该是":visible"
而不是'a')
答案 1 :(得分:0)
$(document).ready(function(){
var $category = $("ul li:gt(5):not(:last)");
$category.hide();
$("input").click(function(){
if($category.is(":visible")){ << corrected spelling ([@serge])
$category.hide();
$("input").attr("value","精简显示")
}
else{
$category.show();
$("input").attr("value","全部显示")
}
}); << added ;
});
在jsfiddle编写代码 - http://jsfiddle.net/9keby/