本節書摘來自異步社區《jQuery、jQuery UI及jQuery Mobile技巧與示例》一書中的第7章,第7.4節,作者:【荷】Adriaan de Jonge , 【美】Phil Dutson著,更多章節內容可以訪問云棲社區“異步社區”公眾號查看
7.4 示例:使用按鈕集裝飾單選框
除了button,jQuery UI還提供了buttonset(按鈕集)。代碼清單7-4演示了如何使用buttonset將一組單選框裝飾成普通按鈕的樣式,其中每次只能選中一個按鈕。
代碼清單7-4 裝飾一組單選框
00 <!DOCTYPE html>
01
02 <html lang="en">
03 <head>
04 <title>jQuery UI Radio</title>
05 <link type="text/css" rel="stylesheet" href=
06 "http://code.jquery.com/ui/1.8.16/themes/base/jquery-ui.css">
07 </head>
08 <body>
09
10 <div id="target">
11 <label for="first">First</label>
12 <input type="radio" name="my-radio" id="first"><br>
13 <label for="second">Second</label>
14 <input type="radio" name="my-radio" id="second"><br>
15 <label for="third">Third</label>
16 <input type="radio" name="my-radio" id="third"><br>
17 </div>
18
19 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
20 <script src="http://code.jquery.com/ui/1.8.16/jquery-ui.min.js">
21 </script>
22
23 <script>
24 // 請將下列代碼移至一個外部的.js文件中
25 $(document).ready(function() {
26
27 $('#target').buttonset();
28
29 });
30 </script>
31 </body>
32 </html>
可以將相似的代碼用于復選框或其他一組傳統的按鈕。