Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 08.04.2012, 03:34
Новичок на форуме
Отправить личное сообщение для stalex242 Посмотреть профиль Найти все сообщения от stalex242
 
Регистрация: 21.03.2012
Сообщений: 6

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


<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';
}
}
Ответить с цитированием
  #2 (permalink)  
Старый 08.04.2012, 04:48
что-то знаю
Отправить личное сообщение для devote Посмотреть профиль Найти все сообщения от devote
 
Регистрация: 24.05.2009
Сообщений: 5,176

Сообщение от stalex242
 if ("t1.onclick = function gas1()") {return d1}else ("t2.onclick = function gas2()") {return d2}
Ужс.. судя по всему вы совсем не знаете языка. Что вы пытаетесь проверить и что в итоге хотите получить?
__________________
хм Russians say завтра but завтра doesn't mean "tomorrow" it just means "not today."
HTML5 history API рассширение для браузеров не поддерживающих pushState, replaceState
QSA CSS3 Selector Engine
Ответить с цитированием
  #3 (permalink)  
Старый 08.04.2012, 07:30
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,495

Да, это даже близко не javascript)
Товарищъ, открою вам глаза: в разных языках программирования, внезапно, разный синтаксис.)
__________________
29375, 35
Ответить с цитированием
  #4 (permalink)  
Старый 08.04.2012, 15:01
Новичок на форуме
Отправить личное сообщение для stalex242 Посмотреть профиль Найти все сообщения от stalex242
 
Регистрация: 21.03.2012
Сообщений: 6

ну вот поэтому прошу помощи, мне надо динамическое изменение текста о планетах в диве при кликах на соответствующие вкладки меню, где названия планет.
Ответить с цитированием
  #5 (permalink)  
Старый 14.04.2012, 02:52
Аватар для w46823
Аспирант
Отправить личное сообщение для w46823 Посмотреть профиль Найти все сообщения от w46823
 
Регистрация: 28.03.2012
Сообщений: 36

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

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

Последний раз редактировалось w46823, 14.04.2012 в 03:05.
Ответить с цитированием
  #6 (permalink)  
Старый 14.04.2012, 03:48
Аватар для w46823
Аспирант
Отправить личное сообщение для w46823 Посмотреть профиль Найти все сообщения от w46823
 
Регистрация: 28.03.2012
Сообщений: 36

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



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
тело функции работает только при наличии alert sstasv Элементы интерфейса 7 31.08.2011 20:05
Не работает функции диологового окна ? IceHell jQuery 1 05.12.2010 03:59
Не работает передача функции переменной Oracool Events/DOM/Window 3 02.12.2010 12:02
Конструкция не пашет в функции , а в событии работает FRIE jQuery 1 05.03.2010 11:38
Подскажите, как работает простой код (замыкание функции)? Dotod Общие вопросы Javascript 5 02.12.2009 04:03