jQuery UI Button option()方法

jQuery UI Button option()方法

jQuery UI由使用HTML、CSS和jQuery实现的GUI部件、视觉效果和主题组成。jQuery UI非常适合为网页建立UI界面。

jQuery UI Button option()方法是用来设置或返回当前与指定元素相关的值。

语法:

  • option(optionName)。返回当前与指定的optionName相关的值。
var isDisabled = $(".selector").button("option", "disabled");
JavaScript
  • option()。它返回包含代表当前按钮选项哈希的键/值对的对象。
var options = $( ".selector" ).button( "option" );
JavaScript
  • option( optionName, value )。它设置与指定的optionName有关的按钮选项的值。
$( ".selector" ).button( "option", "disabled", true );
JavaScript
  • option(选项)。它为按钮元素设置一个或多个选项。
$( ".selector" ).button( "option", { disabled: true } );
JavaScript

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

例子:下面的代码演示了jQuery UI的button()方法。

<!doctype html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <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>
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h3>jQuery UI Button option() Method</h3>
  
        <button>GFG Button</button>
        <br><br>
  
        <input type="button" id="divID" 
               style="padding: 5px 15px;" 
               value="Set option() Method Value">
    </center>
  
    <script>
        (document).ready(function () {
            ("button").button();
  
            ("#divID").on('click', function () {
                ("button").button("option", "disabled", true);
            });
        });
    </script>
</body>
</html>
HTML

输出:

jQuery UI Button option()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册