jQuery UI的Droppable创建事件
jQuery UI是一种基于网络的技术,由各种GUI部件、视觉效果和主题组成。这些功能可以使用jQuery JavaScript库来实现。jQuery UI是为网页建立UI界面的最佳工具。它也可以用来建立高度互动的网络应用程序,或者可以用来轻松地添加小工具。
在这篇文章中,我们将使用jQuery UI的Droppable创建事件,当droppable被创建时触发。
语法:
我们需要用创建一个回调函数来初始化可投放的小组件
$( ".selector" ).droppable({
create : function( event, ui ) {}
});
为drop create事件绑定一个事件监听器。
$( ".selector" ).on( "dropcreate ", function( event, ui ) {} );
参数:这些是可以接受的下列参数。
- event。当分类创建一个项目时,该事件被触发。
- ui。这个参数的类型是对象。ui对象是空的,但为了与其他事件保持一致而包括在内。
CDN链接:下面是一些jQuery Mobile脚本,你的项目将需要这些脚本,所以要把它们添加到你的项目中。
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src= “https://code.jquery.com/jquery-1.12.4.js”></script>
<script src= “https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
例子:这个例子描述了jQuery UI Droppable创建事件的用途。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href=
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel="stylesheet">
<script src=
"https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src=
"https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<style>
.dragg {
width: 90px;
height: 50px;
border: 1px solid black;
background-color: blue;
}
.dropp2 {
width: 200px;
height: 50px;
border: 1px solid black;
float: center;
background-color: green;
}
</style>
<script>
(function () {
(".dragg").draggable();
(".dropp2").droppable({
create: function (event, ui) {
(".res").html($(".res").html()
+ "<b>Droppable Widget has been created.</b><br>");
}
});
});
</script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksforGeeks</h1>
<h3>jQuery UI Droppable create Event</h3>
<div class="dragg">
<p>Drag</p>
</div>
<br>
<div class="dropp2">
<p>Drop here</p>
</div>
<br>
<div class="res"></div>
</center>
</body>
</html>
输出:
jQuery UI的Droppable创建事件