jQuery和不同的浏览器

时间:2014-08-13 20:26:12

标签: jquery html

我在localhost上的页面需要jQuery和jQuery ui,它适用于localhost中的chrome,Firefox和Internet Explorer 11,但是当我将文件上传到服务器时,jQuery ui不再适用于Internet Explorer 11.这个问题显然在{{{ 3}}但我不明白答案,任何人都可以解释一下吗?

我的代码:

<!doctype html>

<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="edge">
  <!--Here is the css file you are using for your project UI included from CDN (content delivery network)-->
  <link rel="stylesheet" href="js/jquery-ui.css" />

  <!--Here is the main jQuery file included from CDN.You can you any other source-->
  <script src="js/jquery-1.9.1.js"></script>

  <!--Here is jQuery UI added from CDN-->
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <!-- Custom styles for the interface goes here -->
  <style>
  #draggable { 
  background: none repeat scroll 0 0 #33CCFF;
    color: #FFFFFF;
    font-family: verdana;
    height: 150px;
    padding: 0.5em;
    text-align: center;
    width: 150px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
}   
  </style>

  <!-- Draggable script goes here -->
  <script>
  $(function() {
  alert();
  //Select the element of the page you want to make draggable and add the function 
  //.draggable() after that
      $( "#draggable" ).draggable();
  });
  </script>
</head>
<body>

 <!-- In that case this div with id of #draggable draggable here 
 and any conmonent inside that draggable div will be also draggable with that -->
<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
</div>


</body>
</html>

1 个答案:

答案 0 :(得分:1)

对于另一个问题的答案,问题可能是由于愚蠢的IE进入兼容模式。您需要将此行放在<head>标记之后:

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

您还需要使用DOCTYPE。您的HTML文件需要看起来像:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <!-- Your title, meta, link and script tags goes here -->
</head>
<body>
    <!-- Your Body tags goes here -->
</body>
</html>

X-UA-Compatible元标记告诉IE作为最新可能的版本工作,而不是进入兼容模式(例如模拟IE7)。