js无法合并到php页面

时间:2013-09-21 16:04:06

标签: javascript php show-hide

我有以下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> 

以上代码在"bare" php page

完全正常

当我将它合并到我的主页面时,js链接不再起作用。我相信我的安排可能有误(诚然,课程和ids仍然让我困惑)。

This is the page where the link appears, but does not work.

请帮忙......

1 个答案:

答案 0 :(得分: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';
    }
}

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