简体   繁体   English

div上的jQuery hide()和show()无法正常工作

[英]jQuery hide() and show() on div not working

jQuery hide() on button not working, followed then show() of div doesn't appear. 按钮上的jQuery hide()无法正常工作,然后div的show()不会出现。 Where it was went wrong? 哪里出错了?

But, it's working fine when internet is turned off. 但是,当关闭互联网时,它工作正常。 jQuery library was hosted locally. 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();
  });
});

Like said earlier, above code works fine when internet turned off. 就像前面说过的,当Internet关闭时,上面的代码可以正常工作。 Also, tried the same with JS display:none and display:block, not working. 另外,尝试对JS display:none和display:block进行同样的操作,但不起作用。

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

Make sure that when you make a fiddle, the jQuery library is imported. 确保在摆弄小提琴时,会导入jQuery库。 Instead of giving the div a display:none you can use the .hide() function in jQuery when the document is ready . document ready时,可以在jQuery中使用.hide()函数,而不是给div一个display:none Here's the fiddle -> https://jsfiddle.net/rr1gwyr7/2/ 这是小提琴-> https://jsfiddle.net/rr1gwyr7/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM