问题描述:

Im trying to get jQuery to run in IE8 so i created the example to test.

<!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?

网友答案:

Here, mainly you need to add !important

Add background-color: red !important; as say for example _bgcolor class in css and add that css _bgcolor class in javascript as following:

  $(document).ready(function(){ 

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

  });
网友答案:

Just add"http:" before the url start.

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

In Jquery css official documentation I found:

Retrieval of shorthand CSS properties (e.g., margin, background, border), although functional with some browsers, is not guaranteed. For example, if you want to retrieve the rendered border-width, use: $( elem ).css( "borderTopWidth" ), $( elem ).css( "borderBottomWidth" ), and so on.

Blockquote

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

相关阅读:
Top