0

显然我的代码存在我找不到的问题,因为当我单击菜单链接时代码没有运行。我正在创建的基本上是一个菜单,它可以动态更改相邻框的内容,并且菜单链接的外观取决于单击的菜单链接。这是我的代码的简化版本:

HTML:

<td class="instructioncells" colspan="1" width="25%">
<a href="#" onclick="helpmenu(showid)" class="link" id="dashboardlink" style="color:      
black; text-decoration: none;">The My Marketing Dashboard</a>
<div style="height:4px;">&nbsp;</div>
<a href="#" onclick="helpmenu(showid)" class="link" id="methodlink">Selecting a    
Method</a>
</td>
<td width="75%" style="vertical-align: top;">

<div id="mymarketingdashboard" style="display: block;">
<div class="font4" style="text-align: center">
The My Marketing Dashboard
</div>
</div>

<div id="selectmethod" style="display: none;">
<div class="font4" style="text-align: center">
Selecting a Method
</div>
</div>

</td>

Javascript:

function helpmenu(showid) 
{
    var showdashboard = document.getElementById("mymarketingdashboard");
    var showmethod = document.getElementById("selectmethod");

    var mymarketing = document.getElementById("dashboardlink");
    var method = document.getElementById("methodlink");

    if (showid == "dashboardlink") 
    {
        showdashboard.style.display = "block";
        mymarketing.style.color = "black";
        mymarketing.style.textDecoration = "none";
        showmethod.style.display = "none";
        method.style.color = "#2C3A7F";
        method.style.textDecoration = "underline";
    }

    if (showid == "methodlink") 
    {
        showdashboard.style.display = "none";
        mymarketing.style.color = "#2C3A7F";
        mymarketing.style.textDecoration = "underline";
        showmethod.style.display = "block";
        method.style.color = "black";
        method.style.textDecoration = "none";
    }

任何有关查找代码未按原样运行的原因的帮助都会很棒。提前非常感谢。

4

1 回答 1

0

我对您的代码进行了一些更改:

Javascript

helpmenu = function (showid) 
{
    var showdashboard = document.getElementById("mymarketingdashboard");
    var showmethod = document.getElementById("selectmethod");

    var mymarketing = document.getElementById("dashboardlink");
    var method = document.getElementById("methodlink");

    if (showid == "dashboardlink") 
    {
        showdashboard.style.display = "block";
        mymarketing.style.color = "black";
        mymarketing.style.textDecoration = "none";
        showmethod.style.display = "none";
        method.style.color = "#2C3A7F";
        method.style.textDecoration = "underline";
    }
    if (showid == "methodlink") {
        showdashboard.style.display = "none";
        mymarketing.style.color = "#2C3A7F";
        mymarketing.style.textDecoration = "underline";
        showmethod.style.display = "block";
        method.style.color = "black";
        method.style.textDecoration = "none";
    }
}

标记

<table><tr><td class="instructioncells" colspan="1" width="25%">
<a href="#" onclick="helpmenu(this.id)" class="link" id="dashboardlink" style="color:      
black; text-decoration: none;">The My Marketing Dashboard</a>
<div style="height:4px;">&nbsp;</div>
<a href="#" onclick="helpmenu(this.id)" class="link" id="methodlink">Selecting a    
Method</a>
</td>
<td width="75%" style="vertical-align: top;">

<div id="mymarketingdashboard" style="display: block;">
<div class="font4" style="text-align: center">
The My Marketing Dashboard
</div>
</div>

<div id="selectmethod" style="display: none;">
<div class="font4" style="text-align: center">
Selecting a Method
</div>
</div>

    </td></tr></table>

jsFiddle:http: //jsfiddle.net/UxQD9/1/

我只是将单击的锚点的 id 传递给helpmenu函数。

于 2013-04-05T20:16:40.773 回答