<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI 拖动(Draggable) - 默认功能</title>
  <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
  <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="jqueryui/style.css">
  <style>
  #draggable { width: 150px; height: 150px; padding: 0.5em; }
  </style>
  <script>
  $(function() {
    $( "div[name=a]" ).draggable();
  });
  </script>
</head>
<body>
 
<div name="a" class="ui-widget-content">
  <p>请拖动我!</p>
</div>
<div name="a" class="ui-widget-content">
  <p>请拖动我!</p>
</div>
<div name="a" class="ui-widget-content">
  <p>请拖动我!</p>
</div>
 
 
</body>
</html>

解决方案 »

  1.   

    你好厉害  div[name=a]这个是什么写法 我没见过 百度什么关键字才能知道?
      

  2.   

    这里http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp
      

  3.   

    多看下api,选择器的问题。。
      

  4.   

     我还是不明白 为什么不能直接用$('#draggable")   而是用$( "div[name=a]" )
      

  5.   

    直接用$('#draggable")  也可以
    那几个div 的id要设成 draggable
      

  6.   

    直接用$('#draggable")  也可以
    那几个div 的id要设成 draggable<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery UI 拖动(Draggable) - 默认功能</title>
      <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
      <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
      <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
      <link rel="stylesheet" href="jqueryui/style.css">
      <style>
      #draggable { width: 150px; height: 150px; padding: 0.5em; }
      </style>
      <script>
      $(function() {
        $( "#draggable" ).draggable();
      });
      </script>
    </head>
    <body>
     
    <div id="draggable" class="ui-widget-content">
      <p>请拖动我!</p>
    </div>
     <div id="draggable" class="ui-widget-content">
      <p>请拖动我!</p>
    </div>
     
    </body>
    </html>
    哈哈不行
      

  7.   

    ID 是唯一标示符,这里不支持这种写法
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery UI 拖动(Draggable) - 默认功能</title>
      <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
      <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
      <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
      <link rel="stylesheet" href="jqueryui/style.css">
      <style>
      #draggable { width: 150px; height: 150px; padding: 0.5em; }
      </style>
      <script>
      $(function() {
        $( ".ui-widget-content" ).draggable();
      });
      </script>
    </head>
    <body>
     
    <div id="draggable" class="ui-widget-content">
      <p>请拖动我!</p>
    </div>
    <div id="draggable" class="ui-widget-content">
      <p>请拖动我!</p>
    </div>
    <div id="draggable" class="ui-widget-content">
      <p>请拖动我!</p>
    </div>
     
     
    </body>
    </html>