首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在页面加载中扩展我的部门?

如何在页面加载中扩展我的部门?
EN

Stack Overflow用户
提问于 2016-09-23 10:18:51
回答 4查看 421关注 0票数 1

我试过所有与我的查询相关的问题,但都找不到正确的解决方案。现在我已经通过使用slideToggle找到了我的解决方案。现在我要我的所有div在页面加载上扩展。

Fiddle演示 这里

片段在下面的示例

代码语言:javascript
复制
$('.expand').click(function(){
    target_num = $(this).attr('id').split('-')[1];
    content_id = '#expandable-'.concat(target_num);
    $(content_id).slideToggle('fast');
});
代码语言:javascript
复制
.expand {
    font-weight: bold;
    font-style: italic;
    font-size: 12px;
    cursor: pointer;
}
.expandable {
    display:none;
}
div {
    margin: 10px;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <p class="expand" id="expand-1">more 1...</p>
</div>
<div class="expandable" id="expandable-1">
    <p>1. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>
<div>
    <p class="expand" id="expand-2">more 2...</p>
</div>
<div class="expandable" id="expandable-2">
    <p>2. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-09-23 10:20:36

将您的风格更新为:

代码语言:javascript
复制
.expandable {
    display:block;
}

现在,在页面加载时,所有div都是展开默认的。

票数 2
EN

Stack Overflow用户

发布于 2016-09-23 10:24:24

案例1 : Place $( ".expandable:first" ).slideToggle('fast'); on document ready。它将在装载时扩展第一个div。

请查看下面的片段,以获得更多的理解。

代码语言:javascript
复制
$('.expand').click(function(){
    target_num = $(this).attr('id').split('-')[1];
    content_id = '#expandable-'.concat(target_num);
    $(content_id).slideToggle('fast');
});
$(document).ready(function(){
  $( ".expandable:first" ).slideToggle('fast');
});
代码语言:javascript
复制
.expand {
    font-weight: bold;
    font-style: italic;
    font-size: 12px;
    cursor: pointer;
}
.expandable {
    display:none;
}
div {
    margin: 10px;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <p class="expand" id="expand-1">more 1...</p>
</div>
<div class="expandable" id="expandable-1">
    <p>1. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>
<div>
    <p class="expand" id="expand-2">more 2...</p>
</div>
<div class="expandable" id="expandable-2">
    <p>2. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>

Case 2:在文档就绪上放置$( ".expandable" ).slideToggle('fast');。它将在装载时扩展所有的div。

请查看下面的片段,以获得更多的理解。

代码语言:javascript
复制
$('.expand').click(function(){
    target_num = $(this).attr('id').split('-')[1];
    content_id = '#expandable-'.concat(target_num);
    $(content_id).slideToggle('fast');
});
$(document).ready(function(){
  $( ".expandable" ).slideToggle('fast');
});
代码语言:javascript
复制
.expand {
    font-weight: bold;
    font-style: italic;
    font-size: 12px;
    cursor: pointer;
}
.expandable {
    display:none;
}
div {
    margin: 10px;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <p class="expand" id="expand-1">more 1...</p>
</div>
<div class="expandable" id="expandable-1">
    <p>1. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>
<div>
    <p class="expand" id="expand-2">more 2...</p>
</div>
<div class="expandable" id="expandable-2">
    <p>2. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>

票数 1
EN

Stack Overflow用户

发布于 2016-09-23 10:24:30

编辑:是你想要的吗?

代码语言:javascript
复制
$(document).ready(function(){
    $('.expand').click();
});

$('.expand').click(function(){
    target_num = $(this).attr('id').split('-')[1];
    content_id = '#expandable-'.concat(target_num);
    $(content_id).slideToggle('fast');
});
代码语言:javascript
复制
.expand {
    font-weight: bold;
    font-style: italic;
    font-size: 12px;
    cursor: pointer;
}
.expandable {
    display:none;
}
div {
    margin: 10px;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <p class="expand" id="expand-1">more 1...</p>
</div>
<div class="expandable" id="expandable-1">
    <p>1. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>
<div>
    <p class="expand" id="expand-2">more 2...</p>
</div>
<div class="expandable" id="expandable-2">
    <p>2. This is the content that was hidden before, but now is... Well, visible!"</p>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39658337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档