重新打开切换开关后重新加载页面

时间:2016-10-13 22:15:50

标签: javascript java jquery spring-mvc toggle

我希望在切换回切换到数据后重新加载页面 JSP:

<input type="checkbox" class="expander" id="toggle"
                                data-on="Portfolio" data-off="Topology" checked
                                data-toggle="toggle" data-onstyle="success">
</div>

Jquery:

$(document).ready(function() {
    var count = 0;
    $('#toggle').change(function() {
        if (this.checked)
            $('#project-list-area').fadeIn('slow'),
            $('#topology').fadeOut('slow');
            count++;
        if (count === 2)
            window.location.reload;
        else
            $('#topology').fadeIn('slow'),
            $('#project-list-area').fadeOut('slow');

    });
});

2 个答案:

答案 0 :(得分:0)

您需要为if使用括号,并且else if超过1行。

此外,window.location.reload()是一种方法,因此您需要使用括号。

$(document).ready(function() {
  var count = 0;
  $('#toggle').change(function() {
      if (this.checked){
          $('#project-list-area').fadeIn('slow'),
          $('#topology').fadeOut('slow');
          count++;
      }

      if (count === 2) 
          window.location.reload();

      else{
          $('#topology').fadeIn('slow'),
          $('#project-list-area').fadeOut('slow');
      }

  });
});

清理了一下,看看toggleFade()

$(document).ready(function() {
  var count = 0;

  $('#toggle').change(function() {
      if (this.checked) count++;
      if (count === 2) window.location.reload();

      $('#topology').fadeToggle('slow'),
      $('#project-list-area').fadeToggle('slow');
  });
});

答案 1 :(得分:-1)

用户if($(this).prop(“checked”))而不是if(this.checked)和window.location.reload();是一种方法

$(document).ready(function () {
    var count = 0;
    $('#toggle').change(function () {
        if ($(this).prop("checked")) {
            $('#project-list-area').fadeIn('slow'),
            $('#topology').fadeOut('slow');
        }
        count++;
        if (count === 2)
            window.location.reload();
        else {
            $('#topology').fadeIn('slow'),
            $('#project-list-area').fadeOut('slow');
        }

    });
});
相关问题