Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   if _ else не работает в функции (https://javascript.ru/forum/dom-window/27283-if-_-else-ne-rabotaet-v-funkcii.html)

stalex242 08.04.2012 03:34

if _ else не работает в функции
 
Проблема с условием , хочу чтоб в диве заменялсь взаимно 1 и 2 планеты при клике на их указатели. не выходит уже 2 недели. сам до ума довести не могу. помогите:help:


<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
 <link rel="stylesheet" href="css/project3.css"> 
 <script language="javascript" type="text/javascript" src="scripts/project3.js"></script>
 <title>Library</title>
</head>
<body >
<table class="planets">
<thead>
<tr>
<th id="pl1" class="normal;selected" onMouseOver="this.className='selected'" onMouseOut="this.className='normal'" onclick="init(div1),gas1()">Mercury</th>
<th id="pl2" class="normal;selected" onMouseOver="this.className='selected'" onMouseOut="this.className='normal'" onclick="init(div1),gas2()">Venus</th>
</tr>
</thead>
</table>
<table id="description">
<div id="div1" class="text"></div>
</table>
</body>
</html>


function init(div1) {
var tabola1 = document.createElement("table");
	div1.appendChild(tabola1);
	var row1 = tabola1.insertRow();
	var row2 = tabola1.insertRow();
	var row3 = tabola1.insertRow();
	var row4 = tabola1.insertRow();
		var cell1 = row1.insertCell();
		var cell2 = row2.insertCell();
		var cell3 = row3.insertCell();
		var cell4 = row4.insertCell();
			cell1.innerHTML = "Mercury is the innermost and smallest planet in the Solar System. The orbit of Mercury has the highest eccentricity of all the Solar System planets, and it has the smallest axial tilt.<br>It completes three rotations about its axis for every two orbits. The perihelion of Mercury's orbit precesses around the Sun at an excess of 43 arcseconds per century, a phenomenon that was explained in the 20th century by Albert Einstein's General Theory of Relativity.Mercury is bright when viewed from Earth, ranging from 2.3 to 5.7 in apparent magnitude, but is not easily seen as its greatest angular separation from the Sun is only 28.3°.<p></p>Comparatively little is known about Mercury; ground-based telescopes reveal only an illuminated crescent with limited detail. The first of two spacecraft to visit the planet was Mariner 10, which mapped about 45% of its surface from 1974 to 1975. The second is the MESSENGER spacecraft, which after three Mercury flybys between 2008 and 2009, attained orbit around Mercury on March 17, 2011, to study and map the rest of the planet.";
			cell2.innerHTML = "<b>Position from the Sun:</b>1";
			cell3.innerHTML = "<b>Name:</b>Mercury";
			cell4.innerHTML = "<b>Mercury</b>";
		var tabola2 = document.createElement("table");
		div1.appendChild(tabola2);
		var row1 = tabola2.insertRow();
		var row2 = tabola2.insertRow();
		var row3 = tabola2.insertRow();
		var row4 = tabola2.insertRow();
		var cell1 = row1.insertCell();
		var cell2 = row2.insertCell();
		var cell3 = row3.insertCell();
		var cell4 = row4.insertCell();
			cell1.innerHTML = "Venus is the second planet from the Sun, orbiting it every 224.7 Earth days. <br>The planet is named after Venus, the Roman goddess of love and beauty. After the Moon, it is the brightest natural object in the night sky, reaching an apparent magnitude of ?4.6, bright enough to cast shadows. Because Venus is an inferior planet from Earth, it never appears to venture far from the Sun: its elongation reaches a maximum of 47.8°. Venus reaches its maximum brightness shortly before sunrise or shortly after sunset, for which reason it has been known as the Morning Star or Evening Star.<p>Venus is classified as a terrestrial planet and it is sometimes called Earth's sister planet owing to their similar size, gravity, and bulk composition. Venus is covered with an opaque layer of highly reflective clouds of sulfuric acid, preventing its surface from being seen from space in visible light.</p>";
			cell2.innerHTML = "<b>Position from the Sun:</b>2";
			cell3.innerHTML = "<b>Name:</b>Venus";
			cell4.innerHTML = "<b>Venus</b>";
			tabola2.style.display = 'none';
tabola1.style.display = 'none';
var t1 = document.getElementById("pl1");
var t2 = document.getElementById("pl2");
			if ("t1.onclick = function gas1()") {return d1}
else ("t2.onclick = function gas2()") {return d2}
var d1 = function gas1() {
tabola2.style.display = 'none';
tabola1.style.display = 'block';
}
var d2 = function gas2() {
tabola1.style.display = 'none';
tabola2.style.display = 'block';
}
}

devote 08.04.2012 04:48

Цитата:

Сообщение от stalex242
 if ("t1.onclick = function gas1()") {return d1}else ("t2.onclick = function gas2()") {return d2}

Ужс.. судя по всему вы совсем не знаете языка. Что вы пытаетесь проверить и что в итоге хотите получить?

Aetae 08.04.2012 07:30

Да, это даже близко не javascript)
Товарищъ, открою вам глаза: в разных языках программирования, внезапно, разный синтаксис.)

stalex242 08.04.2012 15:01

ну вот поэтому прошу помощи, мне надо динамическое изменение текста о планетах в диве при кликах на соответствующие вкладки меню, где названия планет.

w46823 14.04.2012 02:52

За свой скрипт не отвечаю (так как учу JavaScript меньше вашего), но думаю, что это должно выглядеть так:

http://learn.javascript.ru/play/GgGP3

w46823 14.04.2012 03:48

Кстати, отличный самоучитель JavaScript
http://learn.javascript.ru/


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