javascript 如何设置默认隐藏? 5

有下列一段js,默认是全部显示,点击后可隐藏,请问如何设置默认即为全部隐藏呢?<---------------以下是js文件------------------>//th... 有下列一段js,默认是全部显示,点击后可隐藏,请问如何设置默认即为全部隐藏呢?

<---------------以下是js文件------------------>

// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {

// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='Show';
var hideText='Hide';

// initialise the visibility check
var is_visible = true;

// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggle').prev().append(' <a href="#" class="toggleLink">'+hideText+'</a>');

// hide all of the elements with a class of 'toggle'
$('.toggle').show();

// capture clicks on the toggle links
$('a.toggleLink').click(function() {

// switch visibility
is_visible = !is_visible;

// change the link text depending on whether the element is shown or hidden
if ($(this).text()==showText) {
$(this).text(hideText);
$(this).parent().next('.toggle').slideDown('slow');
}
else {
$(this).text(showText);
$(this).parent().next('.toggle').slideUp('slow');
}

// return false so any link destination is not followed
return false;

});
});
展开
 我来答
modao1221
2012-06-18 · TA获得超过108个赞
知道小有建树答主
回答量:203
采纳率:0%
帮助的人:154万
展开全部
记住在js中对布尔变量进行赋初始值时,尽量赋为false。这样可以避免你在下面的操作中,假如条件不满足的话,直接跳出if,而避免代码崩溃!
追问
好的,请问您有qq吗?加934781633,谢谢!
rauphern
2012-06-18 · 超过20用户采纳过TA的回答
知道答主
回答量:109
采纳率:0%
帮助的人:51.3万
展开全部
var is_visible = true;
把这句话改成
var is_visible = false;
追问
按您说的,依然是全部都显示出来了,请问您有qq吗?加934781633,谢谢!
追答
在公司不能上QQ~~
刚那个看错了
应该是把$('.toggle').show();
换成$('.toggle').hide();
var is_visible = true;这句话好像没排上用场
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式