jQuery UI Selectable appendTo选项
jQuery UI由GUI小工具、视觉效果和使用jQuery JavaScript库实现的主题组成。jQuery UI对于构建网页的UI界面非常有用。它可以用来建立高度互动的网络应用程序,也可以用来轻松地添加小工具。
jQuery UI Selectable appendTo选项是用来设置和获取选择助手应该被附加到哪个元素上。
语法:
用appendTo选项初始化可选择的元素。
$( ".selector" ).selectable({
appendTo: "#element"
});
- 获取appendTo选项。
var appendTo= $( "Selector" ).selectable( "option", "appendTo" );
- 设置appendTo选项。
$( "Selector" ).selectable( "option", "appendTo", "#element" );
CDN链接:下面是一些jQuery Mobile脚本,你的项目将需要这些脚本,所以要把它们添加到你的项目中。
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/smoothness/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 Mobile Selectable appendTo选项的用途。
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href=
"https://code.jquery.com/ui/1.12.1/themes/smoothness/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>
<style>
h1 {
color: green;
}
#list .ui-selecting {
background: greenyellow;
}
#list .ui-selected {
color: white;
background: green;
}
#Button
{
padding: 0.5;
font-size: 20px;
height: 50px;
width: 40%;
background:green;
}
</style>
<script>
(document).ready(function() {
("#Button").on('click', function() {
var appendTo = ("#list").selectable(
"option", "appendTo");
("#gfg").html("Selectable are appended to: "+
appendTo);
});
});
</script>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h3>jQuery UI Selectable distance Option</h3>
<ul id="list" style="list-style: none">
<li>Data Structure</li>
<li>Algorithm</li>
<li>C++</li>
<li>Java</li>
<li>HTML</li>
<li>Bootstrap</li>
<li>PHP</li>
</ul>
<input type="button"
id="Button"
value="Click">
<h3>
<span id="gfg"></span>
</h3>
</center>
<script>
(document).ready(function() {
("#list").selectable();
});
</script>
</body>
</html>
输出:
jQuery UI Selectable appendTo选项