javascript:ReverseDisplay not working

javascript:ReverseDisplay not working

本文关键字:working not ReverseDisplay javascript      更新时间:2023-09-26

我有一个使用javascript的页面:ReverseDisplay。它突然不工作了。我不是一个大的javascript人,所以我想知道是否有人可以帮助我找出什么是错的。页面如下:http://www.smbgc.org/about/volunteer/

这是一个可折叠div和页面底部的脚本:

<div id="youth" class="bluelink" style="padding-bottom: 50px;">
    <a href="javascript:ReverseDisplay('youthinfo')">
        <span style="font-weight: 800; font-size: 24px;">Youth Volunteers</span>
    </a>
    <span>Youth volunteers are high school students who are interested in giving back to their community while learning meaningful leadership and job skills. <strong>Youth volunteers are valuable role models for younger members and often are assisting them with programs, homework, & sports in addition to special planned activities by our Teen staff.</strong></span>
    <a href="javascript:ReverseDisplay('youthinfo')">
        <strong>Click to learn more!</strong>
    </a>
    <div id="youthinfo" class="bluelink" style="display: none; padding-left: 30px;">
        &nbsp; All <strong>Youth Volunteers</strong> must be a current member of the Boys & Girls Clubs of Santa Monica or commit to volunteer for 30 hours within a 3 month period. 
        To become a member, <a href="http://www.smbgc.org/about/join/">click here</a>. 
        Youth Volunteers are enrolled in our Leaders in Training Program, and report to the <strong>Director of Volunteer Services, Jessica Rubecindo</strong>. 
        All participants in the LIT program are expected to attend a weekly meeting with Jessica, where they go over program expectations, skills for working with younger members and the community, and upcoming volunteer opportunities. 
        <strong>Questions?</strong> For more information about the Youth Volunteer program, please contact our Director of Volunteer Services <strong>Jessica Rubecindo,</strong> at <strong>jessica@smbgc.org.</strong>
        <a href="javascript:HideContent('youthinfo')">
            <strong>Click to hide above info.</strong>
        </a>
    </div>
</div>
<script type="text/javascript" language="JavaScript">// <![CDATA[
    function HideContent(d) {
        document.getElementById(d).style.display = "none";
    }
    function ShowContent(d) {
        document.getElementById(d).style.display = "block";
    }
    function ReverseDisplay(d) {
    if (document.getElementById(d).style.display == "none") {
            document.getElementById(d).style.display = "block";
        } else {
            document.getElementById(d).style.display = "none";
        }
    }
// ]]></script>

问题是上面的代码不是如何在您的页面中实际呈现的

页面中是这样的

[不要重新格式化这个人有痒编辑!!!!)

<p><script type="text/javascript" language="JavaScript">// <![CDATA[  function HideContent(d) {         document.getElementById(d).style.display = "none";      }       function ShowContent(d) {       document.getElementById(d).style.display = "block";         }       function ReverseDisplay(d) {        if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }      else { document.getElementById(d).style.display = "none"; }         }  // ]]&gt;</script></p>

显示为单行。现在,为什么这是一个问题,因为它与JavaScript注释有关。//注释隐藏了所有的函数

段落标签不应该绕在script标签周围。我会转储CData标签,因为你不使用XHTML。