Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么jquery会起作用。隐藏前页面加载时隐藏闪烁_Jquery - Fatal编程技术网

为什么jquery会起作用。隐藏前页面加载时隐藏闪烁

为什么jquery会起作用。隐藏前页面加载时隐藏闪烁,jquery,Jquery,我正在学习查询,如果类名存在,我会隐藏一个按钮,但是当我加载页面并且类名存在时,按钮会在隐藏前短暂地显示几秒钟,我做错了什么,有没有办法加快速度 这是我的密码 jQuery(document).ready(function($){ // If the imagelinks with classname clonedInput are shown, then hide the add image button if ( $(".clonedInput").length) { $

我正在学习查询,如果类名存在,我会隐藏一个按钮,但是当我加载页面并且类名存在时,按钮会在隐藏前短暂地显示几秒钟,我做错了什么,有没有办法加快速度

这是我的密码

jQuery(document).ready(function($){
  // If the imagelinks with classname clonedInput are shown, then hide the add image button
  if ( $(".clonedInput").length) {
      $('.add-logo-button').hide();
  }
  // When you click clone. hide the button
  $('.add-logo-button').click(function(){
      $(".add-logo-button").hide();
  });
  // When you click remove. show the button
  $('.remove-logo').click(function(){
      $(".add-logo-button").show();
  });
});

当它第一次加载时,执行jquery需要一些时间来隐藏这个元素。此时,直到它执行jquery以隐藏为止,它将显示在页面中


因此,您需要使用css(例如内联样式
display:none
)来显示您在页面加载中隐藏的元素。如果您内联css,它将在html加载中执行,并且在任何时候都不会显示。

使用css(例如,
display:none
)不是更容易吗?没有办法加速它,它会等待DOM就绪,在某些浏览器中会让您闪烁。解决方案是将元素设置为初始隐藏,并反转条件,用javascript显示,但如果用户禁用了javascript,则永远不会显示该元素。另一个选项是在DOM中的元素后面放置一个脚本标记,并删除DOM就绪处理程序。为什么它必须是内联的?谢谢,添加了这个,现在就可以了。@j08691:实际上它需要css来隐藏it@user1221565:如果答案有效,请不要忘记标记:)我知道CSS是解决方案,我的问题是为什么你说它必须是内联的?