jQuery UI Slider instance()方法
jQuery UI由使用HTML、CSS和jQuery实现的GUI部件、视觉效果和主题组成。jQuery UI非常适合为网页建立UI界面。
滑块小部件帮助我们使用给定的范围获得某个值。我们可以通过滑动来改变滑块的值。instance()方法被用来返回滑块的实例对象。如果滑块元素没有相关的元素,那么它返回未定义。
语法:
$( ".selector" ).slider( "instance" );
参数:该方法不接受任何参数。
返回值:该方法返回滑块实例对象。
CDN链接:首先,添加你的项目需要的jQuery UI脚本。
<link rel=”stylesheet” href=”//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css”>
<script src=”//code.jquery.com/jquery-1.12.4.js”></script>
<script src=”//code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
例子:这个例子描述了jQuery UI Slider instance()方法。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> jQuery UI Slider instance() Method </title>
<link rel="stylesheet" href=
"//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src=
"//code.jquery.com/jquery-1.12.4.js"></script>
<script src=
"//code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<style>
h1 {
color: green;
}
#divID {
width: 600px;
}
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h2>jQuery UI Slider instance() Method</h2>
<div id="divID"></div>
<br>
<input type="button" id="btn"
value="Slider Instance Value"
style="padding: 5px 15px;">
<br>
<div id="res"></div>
</center>
<script>
(function () {
("#divID").slider();
("#btn").on('click', function() {
var res =("#divID").slider("instance");
console.log(res);
});
});
</script>
</body>
</html>
输出: