Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   трабл с функциями (https://javascript.ru/forum/dom-window/26778-trabl-s-funkciyami.html)

stalex242 21.03.2012 23:12

трабл с функциями
 
Вложений: 2
проблема с функциями, происходит надожение при выполнении функций, а мне надо чтоб они динамически менялись в диве при выполнении их последовательно. вылаживаю 2 картинки с html и js/. на pl3, pl4 pl5 внимания не обращайте в html. моя задача чтоб контекст и картинки динамично меняли друг друга при клике на 1 или 2 планету а не накладывались. помогите. плизззз

T-sh 21.03.2012 23:28

гениально выкладывать код в скриншотах...

оформите код нормально, для этого при написании поста есть специальные конпки "JS", "HTML" и прочее.. в этой околесице никто разбираться не будет.

stalex242 21.03.2012 23:35

код моего документа
 
<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/project5.js"></script>
 <title>Library</title>
</head>
<body onload="planet()">
<table class="planets">
<thead>
<tr>
<th id="pl1" class="normal;selected" onMouseOver="this.className='selected'" onMouseOut="this.className='normal'">Mercury</th>
</tr>
</thead>
</table>
<div id="div1" class="text"></div>
<img class="pict" id="mer" alt="Current Photo" src="images/mercury.jpg" height="150" width="150"/>
<img class="pict" id="ven" alt="Current Photo" src="images/venus.jpg" height="150" width="150"/>
<div id="div2" class="img"></div>
</body>
</html>

function planet() {
if (document.getElementById('pl1').onclick = pl_1) {
var pl_1 = function tabolaNuova1(div1) {
var tabola = document.createElement("table");
div1.appendChild(tabola);
	var row1 = tabola.insertRow();
	var row2 = tabola.insertRow();
	var row3 = tabola.insertRow();
	var row4 = tabola.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>";
	}
	return pl_1;
	
} else if (document.getElementById('pl2').onclick = pl_2) {
var pl_2 = function tabolaNuova2(div1) {	 
		var tabola = document.createElement("table");
		div1.appendChild(tabola);
		var row1 = tabola.insertRow();
		var row2 = tabola.insertRow();
		var row3 = tabola.insertRow();
		var row4 = tabola.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>";
}
return pl_2;
}
}

T-sh 22.03.2012 09:42

у картинок есть id. по нему и скрывай нужную после клика, а оставшуюся, наоборот делай видимой.

stalex242 23.03.2012 01:03

не работает скрипт
 
та у меня скрипт не пашет я хочу чтоб и текст о каждой планете динамично менялся, но не компилирует ничего. я дето тупанул с логикой

stalex242 23.03.2012 02:37

я почти нашел решение но в условии использую else if а Хром не воспринимает вообще else... почему??


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