1 <head>
2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
3 <title>jqeruy UI 拖拽练习-事件</title>
4 <!--导入jquery插件-->
5 <script type="text/javascript" src="../../js/jquery-1.10.2.min.js"></script>
6 <!--导入jqueryUI插件-->
7 <script type="text/javascript" src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.js"></script>
8 <link rel="stylesheet" type="text/css" href="../../js/jquery-ui-1.10.3.custom/css/ui-lightness/jquery-ui-1.10.3.custom.css"/>
9
10 <!--自写脚本-->
11 <script type="text/javascript" language="javascript">
12 //在页面加载完之后加载jquery
13 $().ready(function(e) {
14 //定义变量
15 var $start_counter=$('#event-start'),
16 $drag_counter=$('#event-drag'),
17 $stop_counter=$('#event-stop'),
18 counts=[0,0,0];
19
20 $("#draggable").draggable({
21 start:function(){
22 //启动开始,总数+1
23 counts[0]++;
24 //修改状态
25 updateCounterStatus($start_counter,counts[0]);
26 } ,
27 drag:function(){
28 //拖拽,总数+1
29 counts[1]++;
30 //修改状态
31 updateCounterStatus($drag_counter,counts[1]);
32 },
33 stop:function(){
34 //结束开始,总数+1
35 counts[2]++;
36 //修改状态
37 updateCounterStatus($stop_counter,counts[2]);
38 }
39 });
40
41 //修改状态
42 function updateCounterStatus($event_counter,new_count)
43 {
44 //判断是否存在该样式
45 if(!$event_counter.hasClass("ui-state-hover"))
46 {
47 $event_counter.addClass("ui-state-hover")
48 .siblings().removeClass("ui-state-hover");
49 }
50 //修改数据
51 $("span.count",$event_counter).text(new_count);
52 }
53 });
54 </script>
55 <!--自写脚本-->
56 <style type="text/css">
57 #draggable { width: 16em; padding: 0 1em; }
58 #draggable ul li { margin: 1em 0; padding: 0.5em 0; } * html #draggable ul li { height: 1%; }
59 #draggable ul li span.ui-icon { float: left; }
60 #draggable ul li span.count { font-weight: bold; }
61 </style>
62 </head>
63
64 <body>
65 <div id="draggable" class="ui-widget ui-widget-content">
66 <p>拖拽我来触发事件链</p>
67 <ul class="ui-helper-reset">
68 <li id="event-start" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-play"></span>"开始" 调用 <span class="count">0</span>x</li>
69 <li id="event-drag" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-arrow-4"></span>"拖拽" 调用 <span class="count">0</span>x</li>
70 <li id="event-stop" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-stop"></span>"结束" 调用 <span class="count">0</span>x</li>
71 </ul>
72 </div>
73 </body>