我正在调用这个 Javascript 函数:
var facing = "First";
function switchit(list){
if (list != facing){
document.getElementById(facing).style.display="none";
};
var listElementStyle=document.getElementById(list).style;
if (listElementStyle.display=="none"){
listElementStyle.display="block";
} else {
listElementStyle.display="none";
}
facing = list;
}
</script>
在嵌套的 div 中,这样当单击超链接时,它将显示一个元素并隐藏另一个元素,如下所示:
<div id="bio">
<!--Ty Expansion -->
<p> <span class="bioEmphasis">What</span> O.L.L.I.E. Lifestyle represents is very personal to me. It has been an aspiration of mine to dedicate myself to the betterment and empowerment of our youth. <a href="javascript:switchit('First')">Click to read more..</a><br />
<div id="First" style="display: none;">
</p>
<hr/><p> <span class="bioEmphasis">Apart</span> of a society where the vast majority of youth are growing up in single parent homes (many in low income neighborhoods). I have witnessed first hand how heavily influenced the youth are by television, music and movies. More Educators, Athletes and Professionals are needed to lend encouragement and guidance on becoming productive members to our environment instead of adapting to a fatal cliché of being a product of their environment.</p>
</div>
<p>
<span class="bioEmphasis">Life is</span> a crazy game!! The trick is to learn how to play! Growing up in New Jersey, the second youngest out of eight, I was fortunate enough to see how the game is NOT supposed to be played. I watched my brothers and sister go through dealing with the law, drugs, and a “content” way of life. This was the beginning of me really wanting to live my life in excellence. <a href="javascript:switchit('Second')">Click to read more..</a><br />
<div id="Second" style="display: none;">
</p>
<hr/><p> <span class="bioEmphasis">All through</span> middle and high school, I was an honor student. Unfortunately, I always was attracted to the “under life”. It seemed like the more popular, in crowd thing to do. I felt like this because of some of my earlier struggles. Having a distinct name and a handicapped brother would fuel my want to be a part of the normal crowd. I can fondly remember being constantly made fun of for being different. Little did I know, what I was doing all along was the right thing and would pay off.</p>
<hr />
</div>
</div>
这些功能可以完美地在较大的 div 容器内一次扩展一个 div 元素。问题是,当我通过单击超链接展开任一元素时...较大的 div 容器(红色渐变方块)将所有内容推到背景之外(实心灰色方块)并搞砸了整个页面的外观,因为 div, (这是几个级别),包含背景是一个固定的宽度,(因为百分比宽度不起作用)。我知道由于用户单击超链接,背景需要动态扩展的确切两个宽度,但我不知道如何从我发布的上述 Javascript 函数中执行此操作。有人对我有任何想法或帮助吗?这非常令人困惑,因为我需要调整大小的 div 是我正在使用的函数调用之外的完整 3 个级别。
div#topwrapper-->div#greySquareH-->div#LeftSide-->div#bioWrapper-->div#bio
并导致在 div#bio 中生成 div#First 或 div#Second。我需要调整 div#greySquareH 高度属性的大小。感谢您提前提供任何帮助!