简体   繁体   English

jQuery IE8无法正常工作,但是IE7,IE6和其他工作正常

[英]jQuery IE8 not working however IE7, IE6 and others work

Im trying to get jQuery to run in IE8 so i created the example to test. 我试图让jQuery在IE8中运行,所以我创建了要测试的示例。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test jQuery</title>
  <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function(){ 

      $("body").css("background", "red");

  });
  </script>
</head>

<body>
hello
</body>
</html>

It works fine in IE6, IE7 and IE9+ however just does not work in IE8, Any ideas? 它在IE6,IE7和IE9 +中可以正常工作,但是在IE8中不起作用,有什么想法吗?

In Jquery css official documentation I found: 在jQuery CSS官方文档中,我发现:

Retrieval of shorthand CSS properties (eg, margin, background , border), although functional with some browsers, is not guaranteed. 尽管某些浏览器可以正常使用CSS速记属性(例如,margin, background ,border),但仍不能保证对其进行检索。 For example, if you want to retrieve the rendered border-width, use: $( elem ).css( "borderTopWidth" ), $( elem ).css( "borderBottomWidth" ), and so on. 例如,如果要检索渲染的边框宽度,请使用:$(elem).css(“ borderTopWidth”),$(elem).css(“ borderBottomWidth”),依此类推。

Blockquote 块引用

try $("body").css( "background-color","red" ) and $ ("body").css( "backgroundColor","red" ) . 尝试$("body").css( "background-color","red" )和$ ("body").css( "backgroundColor","red" )

Here, mainly you need to add !important 在这里,主要需要添加!important

Add background-color: red !important; 添加background-color: red !important; as say for example _bgcolor class in css and add that css _bgcolor class in javascript as following: 例如说在css中的_bgcolor类,并在javascript中添加该css _bgcolor类,如下所示:

  $(document).ready(function(){ 

      $("body").addClass('_bgcolor');

  });

只需在网址开始前添加“ http:”即可。

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

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

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