0

我有以下js代码:

<style>
<!--
body
{
font-family: "century schoolbook", serif;
font-size: 20px;
}
.hidden
{
display: none;
color: #000;
background: #FFFFFF;
}
.unhide
{
display: block;
color: #000;
}
a.unhide
{
text-decoration: none;
}
a.unhide:hover
{
text-decoration: underline;
}
.unhide:hover
{
background: #FFE5B4;
padding: 3px 8px;
display: table-row;
transition: background .25s ease-in-out;
-moz-transition: background .25s ease-in-out;
-webkit-transition: background .25s ease-in-out;
}
-->
</style>
<script type="text/javascript">
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className = (item.className == 'hidden') ? 'unhide' : 'hidden';
}
}
</script>

...
<div class="conBoxcities">
<class id="info">
<a href="javascript:unhide('cityname');" class="unhide">
This is really a js link with a city name. Clicking brings down information about 
that city.
</a>
</class>

<class id="info">
<div id="cityname" class="hidden">
This is where the content of the above link appears. It is just an info blurb,    
basically.
This js script works here. On the other page it does not. I believe I messed up 
somewhere in my classes...please help
</div>
</class>
</div> 

上面的代码在“裸”的 php 页面上运行良好

当我将它合并到我的主页时,js 链接不再起作用。我相信我的安排可能有错误(诚然,班级和身份证仍然让我感到困惑)。

这是出现链接但不起作用的页面。

请帮忙...

4

1 回答 1

2

问题在于,在您的“实时”页面中,您unhide使用以下代码重新定义了函数:

function unhide(divID) {
    var item = document.getElementsByClassName(divID)[0];
    console.log(item);
    console.log(item.className ==  divID + ' hide');
    if (item) {
    item.className = (item.className ==  divID + ' hide') ? divID + ' unhide' : divID + ' hide';
    }
}

如果您删除,我们注释掉该代码,一切都会按预期工作。

于 2013-09-21T16:11:42.663 回答