У меня есть следующий код JS:JS не удается включить в PHP страницу
<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 ссылки больше не функционируют. Я считаю, что у меня может быть ошибка в моей договоренности (по общему признанию, классы и идентификаторы все еще путают меня).
This is the page where the link appears, but does not work.
Пожалуйста, помогите ...
Вы должны посмотреть на свою консоль javascript для ошибок, когда вы получите эту ошибку: 'Uncaught TypeError: Невозможно прочитать свойство 'className' of undefined' –
У вас нет события, которое могло бы« запустить »функцию, сделать ты? Наведите указатель мыши или нажмите? – djot
@djot у него встроенный javascript в теге привязки –