Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   is not define от новичка (https://javascript.ru/forum/misc/11364-not-define-ot-novichka.html)

zerstoren 19.08.2010 23:34

is not define от новичка
 
Здравствуйте коллеги программисты.
Я не давно начал изучать js по учебнику Девида Флэнагана (5е издание)

Но у меня возникают какие-то мне не понятные ошибки в конструкторе.

Код:

<html>
<head><meta http-equiv="content-type" content="text/html; charset=windows-1251" />
<style type="text/css">
.tooltipShadow {
background-color:#333333; margin:3px 3px; }
.tooltypeContent {
background-color:#888888; }
</style>

<script>

function Tooltip( ) {
this.tooltip = document.createElement('div');
this.tooltip.style.position = "absolute";
this.tooltip.style.visibility = "hidden";
this.tooltip.style.className = "tooltipShadow";
//end of shadow DIV
this.content = document.createElement('div');
this.content.style.position = "relative";
this.content.className = 'tooltipContent';

this.tooltip.appendChild(this.content);
}
        Tooltip.prototype.show = function(text, x, y) {
        this.content.innerHTML += text;
        this.tooltip.style.left = x + "px";
        this.tooltip.style.right = y + "px";
        this.tooltip.style.visibility = "visible";

        if(this.tooltip.parentNode != document.body)  document.body.appendChild(this.tooltip);
};

        Tooltip.prototype.hide = function() {
        this.tooltip.style.visibility = "hidden"; };
</script></head>
<body>



<p >Сделать невидимой навсегда</p>
<p><a href="" onMouseOver="show('s',1,1);" onMouseOut="hide();">Куку</a></p>

</body>
</html>

Вот полный код. Ошибку отдает простую и ее содержание понимаю, но не могу понять по какой причине она всплывает :(
show is not define
hide is not define

перепроверил по учебнику содержание пару раз, но результатов на фикс ошибки не получил.
Пожалуйста ткните один раз носом где я ошибся, чтоб более не обращаться по таким глупостям на форум и не спрашивать у людей.

Большое спасибо

рони 20.08.2010 03:09

Функций show и hide у тебя нет самих по себе это протототипы функции Tooltip создай хотябы 1 экземпляр этой функции и потом пользуйся
P.S. названия классов в стиле и скрипте не совпадает

<html>
<head><meta http-equiv="content-type" content="text/html; charset=windows-1251" />
<style type="text/css">
.tooltipShadow {
background-color:#333333; margin:3px 3px; }
.tooltypContent {
background-color:#888888; }
</style>

<script>

function Tooltip( ) {
this.tooltip = document.createElement('div');
this.tooltip.style.position = "absolute";
this.tooltip.style.visibility = "hidden";
this.tooltip.style.className = "tooltipShadow";
//end of shadow DIV
this.content = document.createElement('div');
this.content.style.position = "relative";
this.content.className = 'tooltypContent';

this.tooltip.appendChild(this.content);
}
	Tooltip.prototype.show = function(text, x, y) {
	this.content.innerHTML += text;
	this.tooltip.style.left = x + "px";
	this.tooltip.style.right = y + "px";
	this.tooltip.style.visibility = "visible";

	if(this.tooltip.parentNode != document.body)  document.body.appendChild(this.tooltip);
};

	Tooltip.prototype.hide = function() {
	this.tooltip.style.visibility = "hidden"; };
*!*  
var a = new Tooltip();
*/!*
</script>

</head>
<body>
<p >Сделать невидимой навсегда</p>

<p><a href=""  onmouseover="a.show('s',1,1);"  onmouseout="a.hide();">Куку</a></p>

</body>
</html>

zerstoren 20.08.2010 10:42

Спасибо и +1, теперь мне будет ясно что я делаю не так)


Часовой пояс GMT +3, время: 14:49.