jQuery UI Slider value()方法

jQuery UI Slider value()方法

jQuery UI由GUI部件、视觉效果和使用jQuery、CSS和HTML实现的主题组成。jQuery UI对于构建网页的UI界面非常有用。jQuery UI通过滑块小部件为我们提供了一个滑块控制。滑块可以帮助我们使用一个给定的范围来获得一个特定的值。在这篇文章中,我们将看到如何在jQuery UI滑块中使用value()方法。

value()方法是用来获取滑块的当前值。这个方法有一个子方法叫value(value)方法,在这里我们可以设置滑块的值。

语法:

$( ".selector" ).slider("value");
$( ".selector" ).slider("value", number);
var a = $( ".selector" ).slider("value", number);

参数:

  • value:是一个要设置的数字值。
  • number:它是一个数字值索引,用来获取该值。

CDN链接:首先,添加你的项目需要的jQuery UI脚本。

<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>

例子1:在这个例子中,我们使用了value()方法来获得每次点击的滑块值。

<!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>
  
        <script>
            (function () {
                ("#gfg").slider();
                ("#gfg").slider("value");
            });
            function gfgg() {
                var a =("#gfg").slider("value");
                console.log(a);
            }
        </script>
    </head>
  
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>jQuery UI | slider value() Method</h2>
        <div id="gfg" onclick="gfgg()"></div>
    </body>
</html>

输出:

jQuery UI Slider value()方法

例2:在这个例子中,我们使用了value(value)方法来设置滑块的值,以获得滑块的特定索引,这里是24。

<!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>
  
        <script>
            (function () {
                ("#gfg").slider();
                ("#gfg").slider("value", 24);
            });
            function gfgg() {
                ("#gfg").slider("value");
            }
        </script>
    </head>
  
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>jQuery UI | slider value(value) Method</h2>
        <div id="gfg" onclick="gfgg()"></div>
    </body>
</html>

输出:

jQuery UI Slider value()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程