jQuery UI 包含使用 HTML 、 CSS 和 jQuery 實現的 GUI 小部件、視覺效果和主題。 jQuery UI 非常適合為網頁構建 UI 接口。
jQuery UI 按鈕 option() 方法用於設置或返回當前與指定元素關聯的值。
用法:
- 選項(選項名稱):返回當前與指定 optionName 關聯的值。
var isDisabled = $(".selector").button("option", "disabled");
- option():它返回包含表示當前按鈕選項哈希的鍵/值對的對象。
var options = $( ".selector" ).button( "option" );
- 選項(選項名稱,值):它設置與指定關聯的按鈕選項的值選項名稱.
$( ".selector" ).button( "option", "disabled", true );
- 選項(選項):它為按鈕元素設置一個或多個選項。
$( ".selector" ).button( "option", { disabled: true } );
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>
例子:下麵的代碼演示了button()jQuery UI 的方法。
HTML
<!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>
輸出:
參考: https://api.jqueryui.com/button/#method-option
相關用法
- jQuery UI Button showLabel用法及代碼示例
- jQuery UI Button label用法及代碼示例
- jQuery UI Button iconPosition用法及代碼示例
- jQuery UI Button icon用法及代碼示例
- jQuery UI Button disabled用法及代碼示例
- jQuery UI Button classes用法及代碼示例
- jQuery UI Button create用法及代碼示例
- jQuery UI Button destroy()用法及代碼示例
- jQuery UI Button disable()用法及代碼示例
- jQuery UI Button enable()用法及代碼示例
- jQuery UI Button refresh()用法及代碼示例
- jQuery UI Button instance()用法及代碼示例
- jQuery UI Button widget()用法及代碼示例
- jQuery UI Buttonset destroy()用法及代碼示例
- jQuery UI Buttonset disable()用法及代碼示例
- jQuery UI Buttonset enable()用法及代碼示例
- jQuery UI Buttonset create用法及代碼示例
- jQuery UI Buttonset items用法及代碼示例
- jQuery UI Buttonset widget()用法及代碼示例
- jQuery UI Buttonset refresh()用法及代碼示例
- jQuery UI Buttonset option()用法及代碼示例
- jQuery UI Buttonset disabled用法及代碼示例
- jQuery UI Tabs option()用法及代碼示例
- jQuery UI Tabs collapsible用法及代碼示例
- jQuery UI Tooltips track用法及代碼示例
注:本文由純淨天空篩選整理自ppatelkap大神的英文原創作品 jQuery UI Button option() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。