Модераторы: Sardar, Aliance
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> изчезновение блоков текста. 
:(
    Опции темы
lasalexx
Дата 23.12.2006, 21:30 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 192
Регистрация: 19.7.2004
Где: Tbilisi

Репутация: нет
Всего: 1



Хочу что б при нажатии на ссылку, под ней открывался div. Всего у меня четыре блока:

Код

<html>
<head>
<title>Hidden Paragraphs</title>
<script type="text/javascript">
//<!--

var eps=new Array(0,0,0,0);
var ids=new Array("p1", "p2", "p3", "p4");

function showHide(i)
{
if (eps[i]==0) {document.getElementById(ids[i]).style.visibility="visible"; eps[i]=1}
else {document.getElementById(ids[i]).style.visibility="hidden"; eps[i]=0}

//alert (document.getElementById(ids[i]).style)
}

//-->
</script>
<style>
.d1 {position:static; padding:5px; padding-left:28px; width:450px; visibility:hidden}
</style>
</head>
<body>
<a href="javascript:showHide(0)">First Paragraph</a>
<div id="p1" class="d1">
Britain's U.N. Ambassador Emyr Jones Parry said the changes in the final text "increase
the chances of agreement tomorrow."
"Actually, this is a very nice step forward," Maria Zakharova, spokeswoman for
Russia's U.N. Mission, told two reporters after the meeting.
China's U.N. Ambassador Wang Guangya said the Europeans "tried to build consensus, but
we will have to see by tomorrow morning whether consensus is there."
</div>

<a href="javascript:showHide(1)">Second Paragraph</a>
<div id="p2" class="d1">
The final draft would order all countries to ban the supply of specified materials and
technology that could contribute to Iran's nuclear and missile programs. It would also
impose an asset freeze on key companies and individuals in the country's nuclear and
missile programs named on a U.N. list.
Iran insists its nuclear program is aimed solely at the peaceful production of nuclear
energy, but the Americans and Europeans suspect Tehran's ultimate goal is the production
of nuclear weapons.
</div>

<a href="javascript:showHide(2)">Third Paragraph</a>
<div id="p3" class="d1">
Iranian President Mahmoud Ahmadinejad reiterated Tuesday that possible Security Council
sanctions would not stop Iran from pursuing uranium enrichment, a technology that can be
used to produce nuclear fuel for civilian purposes or fuel for a nuclear bomb.
The resolution authorizes action under Article 41 of Chapter 7 of the U.N. Charter. It
allows the Security Council to impose nonmilitary sanctions such as completely or partially
severing diplomatic and economic relations, transportation and communications links.
</div>

<a href="javascript:showHide(3)">Fourth Paragraph</a>
<div id="p4" class="d1">
Before the final text was circulated, Russia's U.N. Ambassador Vitaly Churkin pressed
for amendments to ensure that Moscow can conduct legitimate nuclear activities in Iran.
Russia is building Iran's first atomic power plant at Bushehr, which is expected to
go on line in late 2007. A reference to Bushehr in the original draft was removed earlier
— as Russia demanded.
</div>
</body>
</html>


как сделать что б когда блока не видно, места между ссылками не остовалось, надо обязательно ставить position:absolute и считать координаты?
PM MAIL WWW ICQ MSN   Вверх
sergejzr
Дата 23.12.2006, 21:37 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Un salsero
Group Icon


Профиль
Группа: Админ
Сообщений: 13285
Регистрация: 10.2.2004
Где: Германия г .Ганновер

Репутация: 10
Всего: 360



Код

document.getElementById(ids[i]).style.display="block";
document.getElementById(ids[i]).style.display="";

И выкинь этот visibility.


--------------------
PM WWW IM ICQ Skype GTalk Jabber AOL YIM MSN   Вверх
lasalexx
Дата 23.12.2006, 21:44 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 192
Регистрация: 19.7.2004
Где: Tbilisi

Репутация: нет
Всего: 1



Код

<html>
<head>
<title>Hidden Paragraphs</title>
<script type="text/javascript">
//<!--

var eps=new Array(0,0,0,0);
var ids=new Array("p1", "p2", "p3", "p4");

function showHide(i)
{
if (eps[i]==0) {document.getElementById(ids[i]).style.display=""; eps[i]=1}
else {document.getElementById(ids[i]).style.display="block"; eps[i]=0}

}

//-->
</script>
<style>
.d1 {position:static; padding:5px; padding-left:28px; width:450px; display: block}
</style>
</head>
<body>
<a href="javascript:showHide(0)">First Paragraph</a>
<div id="p1" class="d1">
Britain's U.N. Ambassador Emyr Jones Parry said the changes in the final text "increase
the chances of agreement tomorrow."
"Actually, this is a very nice step forward," Maria Zakharova, spokeswoman for
Russia's U.N. Mission, told two reporters after the meeting.
China's U.N. Ambassador Wang Guangya said the Europeans "tried to build consensus, but
we will have to see by tomorrow morning whether consensus is there."
</div>

<a href="javascript:showHide(1)">Second Paragraph</a>
<div id="p2" class="d1">
The final draft would order all countries to ban the supply of specified materials and
technology that could contribute to Iran's nuclear and missile programs. It would also
impose an asset freeze on key companies and individuals in the country's nuclear and
missile programs named on a U.N. list.
Iran insists its nuclear program is aimed solely at the peaceful production of nuclear
energy, but the Americans and Europeans suspect Tehran's ultimate goal is the production
of nuclear weapons.
</div>

<a href="javascript:showHide(2)">Third Paragraph</a>
<div id="p3" class="d1">
Iranian President Mahmoud Ahmadinejad reiterated Tuesday that possible Security Council
sanctions would not stop Iran from pursuing uranium enrichment, a technology that can be
used to produce nuclear fuel for civilian purposes or fuel for a nuclear bomb.
The resolution authorizes action under Article 41 of Chapter 7 of the U.N. Charter. It
allows the Security Council to impose nonmilitary sanctions such as completely or partially
severing diplomatic and economic relations, transportation and communications links.
</div>

<a href="javascript:showHide(3)">Fourth Paragraph</a>
<div id="p4" class="d1">
Before the final text was circulated, Russia's U.N. Ambassador Vitaly Churkin pressed
for amendments to ensure that Moscow can conduct legitimate nuclear activities in Iran.
Russia is building Iran's first atomic power plant at Bushehr, which is expected to
go on line in late 2007. A reference to Bushehr in the original draft was removed earlier
— as Russia demanded.
</div>
</body>
</html>


так блоки совсем не исчезают. Или я не так вас понял smile 
PM MAIL WWW ICQ MSN   Вверх
AKS
Дата 23.12.2006, 23:02 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Участник форума
**


Профиль
Группа: Участник
Сообщений: 725
Регистрация: 20.9.2006

Репутация: 27
Всего: 52



Код

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 
'http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='ru'>
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=windows-1251' />
        <title>Untitled Document</title>
        <script type='text/javascript'>
                /*<![CDATA[*/
                function showHide(i) {
                    var o = document.getElementById('p' + i),
                    n = o.className;
                    if (n.indexOf('d2') > -1) {
                        o.className = n.replace(' d2', '');
                    }
                    else {
                        o.className += ' d2';
                    }
                }
                /*]]>*/
        </script>
        <style type='text/css'>
                /*<![CDATA[*/
                .d1 {
                    padding:5px;
                    padding-left:28px;
                    width:450px;
                    display:none;
                }
                .d2 {
                    display:block;
                }
                /*]]>*/
        </style>
    </head>
    <body>
        <p><a href="javascript:showHide(1)">First Paragraph</a></p>
        <div id="p1" class="d1">
            Britain's U.N. Ambassador Emyr Jones Parry said the changes in the final text 
            "increasethe chances of agreement tomorrow."" 
            Actually, this is a very nice step forward," Maria Zakharova, spokeswoman for Russia's U.N. 
            Mission, told two reporters after the meeting. 
            China's U.N. Ambassador Wang Guangya said the Europeans "tried to build consensus, but 
            we will have to see by tomorrow morning whether consensus is there."
        </div>
        <p><a href="javascript:showHide(2)">Second Paragraph</a></p>
        <div id="p2" class="d1">
            The final draft would order all countries to ban the supply of specified materials and 
            technology that could contribute to Iran's nuclear and missile programs. It would also 
            impose an asset freeze on key companies and individuals in the country's nuclear and 
            missile programs named on a U.N. list. 
            Iran insists its nuclear program is aimed solely at the peaceful production of nuclear 
            energy, but the Americans and Europeans suspect Tehran's ultimate goal is the production 
            of nuclear weapons.
        </div>
        <p><a href="javascript:showHide(3)">Third Paragraph</a></p>
        <div id="p3" class="d1">
            Iranian President Mahmoud Ahmadinejad reiterated Tuesday that possible Security Council 
            sanctions would not stop Iran from pursuing uranium enrichment, a technology that can be 
            used to produce nuclear fuel for civilian purposes or fuel for a nuclear bomb. 
            The resolution authorizes action under Article 41 of Chapter 7 of the U.N. Charter. It 
            allows the Security Council to impose nonmilitary sanctions such as completely or partially 
            severing diplomatic and economic relations, transportation and communications links.
        </div>
        <p><a href="javascript:showHide(4)">Fourth Paragraph</a></p>
        <div id="p4" class="d1">
            Before the final text was circulated, Russia's U.N. Ambassador Vitaly Churkin pressed 
            for amendments to ensure that Moscow can conduct legitimate nuclear activities in Iran. 
            Russia is building Iran's first atomic power plant at Bushehr, which is expected to 
            go on line in late 2007. A reference to Bushehr in the original draft was removed earlier 
            — as Russia demanded.
        </div>
    </body>
</html>

PM MAIL   Вверх
lasalexx
Дата 23.12.2006, 23:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 192
Регистрация: 19.7.2004
Где: Tbilisi

Репутация: нет
Всего: 1



sergejzr и AKS
merci beaucoup
 smile 
PM MAIL WWW ICQ MSN   Вверх
tolik777
Дата 25.12.2006, 16:03 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 133
Регистрация: 19.6.2006

Репутация: 1
Всего: 2



У меня тоже проблема с с сокрытием. Правда ошибка в синтаксисе.
Почему браузер ругается на строку:
<input type="checkbox" onClick="document.getElementById('Down').style.visibility = visible;">
Перепробовал все комбинации кавычек, но ничего не помогает.
Или обязательно надо функцию определять, а в ней изменять свойство?
PM MAIL WWW ICQ   Вверх
lasalexx
Дата 25.12.2006, 16:20 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 192
Регистрация: 19.7.2004
Где: Tbilisi

Репутация: нет
Всего: 1



если я не ошибаюсь, то так

Код

<input type="checkbox" onClick="document.getElementById('Down').style.visibility = 'visible';">

PM MAIL WWW ICQ MSN   Вверх
sergejzr
Дата 25.12.2006, 16:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Un salsero
Group Icon


Профиль
Группа: Админ
Сообщений: 13285
Регистрация: 10.2.2004
Где: Германия г .Ганновер

Репутация: 10
Всего: 360



tolik777, ты читал сначала?

Цитата(sergejzr @  23.12.2006,  20:37 Найти цитируемый пост)
И выкинь этот visibility. 


Код

<input type="checkbox" onClick="el=document.getElementById('Down'); el.style.display= (el.style.display=='none' )?'':'none';">



--------------------
PM WWW IM ICQ Skype GTalk Jabber AOL YIM MSN   Вверх
tolik777
Дата 25.12.2006, 17:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 133
Регистрация: 19.6.2006

Репутация: 1
Всего: 2



Читал конечно. Но не понял, для чего нужно выкидывать visibility, что в нем плохого?

Добавлено @ 17:08 
А кажется понял. visibility оставляет место пустое когда скрывается, а если dispay, то место пустое исчезает.
Спасибо!
PM MAIL WWW ICQ   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Форум для вопросов, которые имеются в справочниках, но их поиск вызвал затруднения, или для разработчика требуется совет или просьба отыскать ошибку. Напоминаем: 1) чётко формулируйте вопрос, 2) приведите пример того, что уже сделано, 3) укажите явно, нужен работающий пример или подсказка о том, где найти информацию.
 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | JavaScript: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.1095 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.