Jump to content
  • 0

Проблема с getElementById


0nline
 Share

Question


<html>
<head>
<style type="text/css">
body {margin: 0;
padding: 0;
width: 1200px;
font-family: Verdana;}
#main {position: fixed;
top: 0;
left: 0;
right: 0;
background: green;
height: 70px;
width: 1200px}
#menu {
position: fixed;
bottom: 0;
right: 0;
cursor: default}
#item {background:url('menu.gif') ;
float: right;
padding: 20px;}
#content1 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;
background: gray;}
#content2 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;}
#content3 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;}
</style>
<script type="text/javascript" language="javascript">
function dhide()
{
var div1=getElementById("content1");
var div2=getElementById("content2");
var div3=getElementById("content3");
document.div1.style.visibility="hidden";
document.div2.style.visibility="hidden";
document.div3.style.visibility="hidden";
}
function change_active_div1()
{
var div1=getElementById("content1");
dhide();
document.div1.style.visibility="visible";
}
function change_active_div12()
{
var div2=getElementById("content2");
dhide();
document.div2.style.visibility="visible";
}
function change_active_div3()
{
var div3=getElementById("content3");
dhide();
document.div3.style.visibility="visible";
}
</script>
</head>
<body>
<div id="main">
<h1>Content management panel <b>sc</b></h1>
<div id="menu">
<div id="item" name="item1" onClick="change_active_div1()">
Main
</div>
<div id="item" name="item2" onClick="change_active_div2()">
Content management
</div>
<div id="item" name="item3" onClick="change_active_div3()">
Templates
</div>
</div>
</div>
<div id="content1">
<p>
This is the main page of Smart Core content management framework,<br>
here you can setup your site for yourself
</p>
</div>
<div id="content2">
<p>
This is the page, where you can add and delete some posts, manage<br>
comments and block some IP adresses.
</p>
</div>
<div id="content3">
<p>
Here you cann manage your site templates, add or delete CSS class...
</p>
</div>
</body>
</html>

По идее при нажатии вызывается функция, но отладчик в Chrome пишет

Uncaught ReferenceError: getElementById is not defined

Panel.html:80Uncaught ReferenceError: change_active_div2 is not defined

В чем проблема?

Edited by 0nline
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Повнимательнее надо!

Везде нужно писать document.getElementById()

change_active_div2 is not defined - потому что у тебя - change_active_div12!!

Ещё раз повнимательней смотри на свой код!!!

Edited by DrStrangeLove
  • Like 1
Link to comment
Share on other sites

  • 0

По идее при нажатии вызывается функция, но отладчик в Chrome пишет

Uncaught ReferenceError: getElementById is not defined

Panel.html:80Uncaught ReferenceError: change_active_div2 is not defined

В чем проблема?

В том, что правильная запись document.getElementById

  • Like 1
Link to comment
Share on other sites

  • 0


<html>
<head>
<style type="text/css">
body {margin: 0;
padding: 0;
width: 1200px;
font-family: Verdana;}
#main {position: fixed;
top: 0;
left: 0;
right: 0;
background: green;
height: 70px;
width: 1200px}
#menu {
position: fixed;
bottom: 0;
right: 0;
cursor: default}
#item {background:url('menu.gif') ;
float: right;
padding: 20px;}
#content1 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;
background: gray;}
#content2 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;}
#content3 {position: absolute;
top: 200px;
width: 1200px;
left: 0;
right: 0;
visibility: hidden;}
</style>
<script type="text/javascript" language="javascript">
function dhide()
{
var div1=document.getElementById("content1");
var div2=document.getElementById("content2");
var div3=getElementById("content3");
div1.style.visibility="hidden";
div2.style.visibility="hidden";
div3.style.visibility="hidden";
}
function change_active_div1()
{
var div1=document.getElementById("content1");
dhide();
div1.style.visibility="visible";
}
function change_active_div2()
{
var div2=document.getElementById("content2");
dhide();
div2.style.visibility="visible";
}
function change_active_div3()
{
var div3=document.getElementById("content3");
dhide();
div3.style.visibility="visible";
}
</script>
</head>
<body>
<div id="main">
<h1>Content management panel <b>SC</b></h1>
<div id="menu">
<div id="item" name="item1" onClick="change_active_div1()">
Main
</div>
<div id="item" name="item2" onClick="change_active_div2()">
Content management
</div>
<div id="item" name="item3" onClick="change_active_div3()">
Templates
</div>
</div>
</div>
<div id="content1">
<p>
This is the main page of SC content management framework,<br>
here you can setup your site for yourself
</p>
</div>
<div id="content2">
<p>
This is the page, where you can add and delete some posts, manage<br>
comments and block some IP adresses.
</p>
</div>
<div id="content3">
<p>
Here you cann manage your site templates, add or delete CSS class...
</p>
</div>
</body>
</html>

Исправил, но все равно не работает, пишет

Uncaught ReferenceError: getElementById is not defined

Uncaught ReferenceError: getElementById is not defined

change_active_div3

(anonymous function)

onclick

Edited by 0nline
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy