案例:jQuery UI案例     状态:可编辑再运行    进入竖版
 运行结果 
AخA
        if ( /red|green|blue/.test(key) && (value < 0 || value > 255) ) {
 
1
<!doctype html>
2
<html lang="en">
3
<head>
4
  <meta charset="utf-8">
5
  <title>jQuery UI 部件库(Widget Factory) - 默认功能</title>
6
  <link rel="stylesheet" href="/css/jqu1.10.4/jquery-ui.min.css">
7
  <script src="/js/jqu/jquery.min1.10.2.js"></script>
8
  <script src="/js/jqu/jquery-ui.min1.10.4.js"></script>
9
  <link rel="stylesheet" href="jqueryui/style.css">
10
  <style>
11
  .custom-colorize {
12
    font-size: 20px;
13
    position: relative;
14
    width: 75px;
15
    height: 75px;
16
  }
17
  .custom-colorize-changer {
18
    font-size: 10px;
19
    position: absolute;
20
    right: 0;
21
    bottom: 0;
22
  }
23
  </style>
24
  <script>
25
  $(function() {
26
    // 部件定义,其中 "custom" 是命名空间,"colorize" 是部件名称
27
    $.widget( "custom.colorize", {
28
      // 默认选项
29
      options: {
30
        red: 255,
31
        green: 0,
32
        blue: 0,
33
 
34
        // 回调
35
        change: null,
36
        random: null
37
      },
38
 
39
      // 构造函数
40
      _create: function() {
41
        this.element
42
          // 添加一个主题化的 class
43
          .addClass( "custom-colorize" )
44
          // 防止双击来选择文本
45
          .disableSelection();
46
 
47
        this.changer = $( "<button>", {
48
          text: "改变",