0

Есть код, который, по идеи, скрывает и показывает блок с фильтром. Но он только открывается и больше не закрывается.

function ShowHideFastFilter()
{
    if(document.getElementById('all_form_fast_filter').style.display=='none')   {$("#catalog_fast_filter").attr('innerHTML','скрыть'); $("#all_form_fast_filter").show("slow"); return;}
    if(document.getElementById('all_form_fast_filter').style.display=='block')  {$("#catalog_fast_filter").attr('innerHTML','отобразить'); $("#all_form_fast_filter").hide("slow");  return;}
}
function ShowHideSectionFilter()
{
    if(document.getElementById('all_form_section_filter').style.display=='none')    {$("#catalog_section_filter").attr('innerHTML','скрыть'); $("#all_form_section_filter").show("slow"); return;}
    if(document.getElementById('all_form_section_filter').style.display=='block')   {$("#catalog_section_filter").attr('innerHTML','отобразить'); $("#all_form_section_filter").hide("slow");  return;}
}

В чем я ошибся?

Здесь результат работы. Под навигацией "Быстрый фильтр".

1
  • Боже мой, такая мешанина plain js и jQ...
    – ling
    30 ноя 2011 в 14:19

3 ответа 3

2
if ( $('#all_form_fast_filter').is(':visible') ) {
  $("#catalog_fast_filter").text('отобразить');
  $("#all_form_fast_filter").hide("slow");
  } else {
  $("#catalog_fast_filter").text('скрыть');
  $("#all_form_fast_filter").show("slow");
  }

Это первая функция, далее по аналогии

0

Такое чувство что вы перепутали block и none местами, и код получается какой-то сложный. по нескольку раз одно и то-же проверяете.

0

Можно так:

<div>
  <div>
    <span
      onclick = "
        this.style.display = 'none';
        this.nextElementSibling.style.display = '';
        this.parentElement.nextElementSibling.style.display = '';
      "
      style = 'display: none;'
    >
      Показать
    </span>
    <span
       onclick = "
        this.style.display = 'none';
        this.previousElementSibling.style.display = '';
        this.parentElement.nextElementSibling.style.display = 'none';
      "
    >
      Скрыть
    </span>
  </div>
  <div>
    Моё содержимое
  </div>
</div>

Можно функцией, но менять содержимое - ни в коем случае

P.S: Я не сторонник длинного inline JS, только как пример!!!

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.