让我先说一下,我对这一切都很新,但正在努力学习。话虽如此,我一直在想如何通过按钮ID添加/删除div类。非常感谢任何帮助,因为我需要制作大约200个这样的文本框。附上示例HTML(用于WordPress与Thesis主题)和我正在使用的CSS。我还包括了一个链接到jsfiddle,以便您可以看到我试图实现的内容(但失败了)。
http://jsfiddle.net/EXPH77/rz683/
CSS:
#the_box {
font-family: Georgia, "Times New Roman", Times, serif;
font-weight: 300;
color: #oooooo;
background-color: #ddddee;
width: 320px;
}
.box_header {
padding-top: .5em;
font-weight: 600;
color: #ffffff;
background-color: #477ede;
text-align: center;
height: 25px;
font-size:1.2em;
}
.box_text {
text-align: left;
padding: 1px;
margin-bottom: 3px;
font-size:0.84em;
}
.media {
text-align: center;
padding: 4px;
margin-bottom: 3px;
}
.box_expand {
text-align: left;
padding: 1px;
margin-bottom: 3px;
font-size:0.84em;
}
p.headtext {
color: #000000;
font-weight: 600;
margin-bottom: 3px;
text-align: left;
font-size:1.2em;
}
HTML:
<div id="the_box">
<div class="box_header"> Exercise Title </div>
<div class="media">
<iframe width="300" height="195" src="http://www.youtube.com/embed/Ok97QIq2f4E" frameborder="0" allowfullscreen></iframe>
</div>
<div class="box_text">
<p class="headtext">Muscles</p>
<ul style="list-style: none; ">
<li><strong>Primary:</strong> MM</li>
<li><strong>Secondary:</strong> MM</li>
<button id="addClass">Instructions</button>
<script type="text/javascript">
$("#addClass").click(function () {
$('#the_box').addClass('box_expand');
$("#removeClass").click(function () {
$('#the_box').removeClass('box_expand');
});
</script>
</div> <div class="box_expand">
<p class="headtext">Preparation</p>
<ol>
<li>Instructions</li>
<li>Go</li> <li>Right</li>
<li>Here</li>
</ol>
<p class="headtext">Movement</p>
<ol>
<li>Instructions</li>
<li>Go</li>
<li>Right</li>
<li>Here</li>
</ol>
<p class="headtext">Comments/Tips</p>
<ul>
<li>Instructions</li>
<li>Go</li>
<li>Here</li>
</ul>
</div>
</div>
})
。http://jsfiddle.net/rz683/5/ 在你的标记中没有带有removeClass
类的元素,请发布所有必要的标记并注意 ID 必须是唯一的,如果你有很多框,应该使用类。 - Ram