0

使用 JQuery,是否可以将一个类的所有成员添加到另一个类?在这里,我试图将类的所有成员添加ui-widget-content到类中draggable

http://jsfiddle.net/j8czR/

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Draggable - Auto-scroll</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <style>
    #draggable, #draggable2, #draggable3 { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
    </style>
    <script>
    $(function() {
       $(".draggable").draggable({ scroll: true });
    });
    </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
    <p>Scroll set to true, default settings</p>
</div>

<div style="height: 5000px; width: 1px;"></div>


</body>
</html>​
4

2 回答 2

3

您可以使用.addClass()方法添加指定的类..

$('.ui-widget-content').addClass('draggable');

如果您想根据 id 将类添加到指定的 div 中,您可以这样做

$("#draggable,#draggable2,#draggable3").addClass("draggable");

检查小提琴

于 2012-12-05T21:24:13.737 回答
1

似乎可以使用该addClass( classname )方法执行此操作,如下所述:http: //api.jquery.com/addClass/

于 2012-12-05T21:24:07.890 回答