div上的jQuery hide()和show()不起作用

时间:2016-05-23 15:49:35

标签: javascript jquery html css show-hide

按钮上的jQuery hide()无法正常工作,然后显示div的show()。哪里出了问题?

但是,当互联网关闭时,它的工作正常。 jQuery库在本地托管。

#loading {
    background: url('/img/loading.gif') no-repeat;
    width: 30px;
    height: 30px;
}
<button id="submit" type="submit" disabled>Submit</button>
<div id="loading" style="display:none"></div>
$(document).ready(function () {
  document.getElementById('submit').disabled = false; // enable the button

  $('#submit').click(function () {
        $(this).removeClass("active"); // either $(this) or $('submit')
        $(this).hide(); // either $(this) or $('submit')
        $('#loading').show();
  });
});

如前所述,上面的代码在互联网关闭时工作正常。另外,尝试使用JS display:none和display:block,not working。

https://jsfiddle.net/945ovayj/1/

1 个答案:

答案 0 :(得分:0)

确保在制作小提琴时,导入jQuery库。当display:none.hide()时,您可以在jQuery中使用document函数,而不是给div ready。这是小提琴 - &gt; https://jsfiddle.net/rr1gwyr7/2/

相关问题