简体   繁体   English

removeAttr(“ style”)不起作用

[英]removeAttr(“style”) doesn't work

I have this website: http://thc-cup.ucoz.com/ And to make the login form appear (by pressing the login button) I have to remove the style of the div which is hidden by default and of which I have no control. 我有这个网站: http : //thc-cup.ucoz.com/并显示登录表单(通过按登录按钮),我必须删除div的样式,该样式默认情况下是隐藏的,并且我已经无控制。 I used this code: 我使用以下代码:

<script>$("#baseLogForm").removeAttr("style");</script>

But it is not working, the div from where it should remove the style is still there. 但是它不起作用,应该从中删除样式的div仍然存在。

Why it isn't working? 为什么不起作用? Thanks 谢谢

Your code isn't working because when it runs, your DOM isn't ready. 您的代码无法正常工作,因为它在运行时尚未准备好DOM。

Try this way: 尝试这种方式:

$(document).ready(function(){
  $("#baseLogForm").removeAttr("style");
});

or the shorter way... 或更短的方法...

$(function(){ //<< This is a "shortcut" to $(document).ready()
  $("#baseLogForm").removeAttr("style");
});

BUT... You could simply do a .show() on this form, this will remove the display: none property in the style attribute of your form. 但是...您只需在此表单上执行.show() ,这将删除display: none表单的style属性中的display: none属性。

You should simply use .show() 您应该只使用.show()

  $(document).ready(function(){
      $("#baseLogForm").show();
  });

Note : If you remove style attribute, if there are other css style those will be removed too. 注意 :如果删除style属性,那么如果还有其他CSS样式,那些样式也会被删除。

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

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