jquery - 如何使用 jquery ui 创建自定义控件?

标签 jquery jquery-ui jquery-plugins

我想使用 jquery ui 框架创建一个控件。我知道我必须使用 jquery.ui.widget.js 作为工厂。

我想要创建的这个控件具有与选项卡控件类似的行为。我想创建一个平铺 View ,因此当您在多个 View 面板中选择内容时...它会展开,而其他 View 会折​​叠到控件的一侧。 喜欢这个http://demos.telerik.com/silverlight/#TileView/FirstLook 有没有逐步创建自定义小部件的教程?

最佳答案

有关此主题的 jQuery UI 文档是一个很好的起点:http://wiki.jqueryui.com/w/page/12138135/Widget-factory

您的小部件至少必须实现以下代码(示例取自文档):

(function( $ ) {
  $.widget( "demo.multi", {

    // These options will be used as defaults
    options: { 
      clear: null
    },

    // Set up the widget
    _create: function() {
    },

    // Use the _setOption method to respond to changes to options
    _setOption: function( key, value ) {
      switch( key ) {
        case "clear":
          // handle changes to clear option
          break;
      }

      // In jQuery UI 1.8, you have to manually invoke the _setOption method from the base widget
      $.Widget.prototype._setOption.apply( this, arguments );
      // In jQuery UI 1.9 and above, you use the _super method instead
      this._super( "_setOption", key, value );
    },

    // Use the destroy method to clean up any modifications your widget has made to the DOM
    destroy: function() {
      // In jQuery UI 1.8, you must invoke the destroy method from the base widget
      $.Widget.prototype.destroy.call( this );
      // In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
    }
  });
}( jQuery ) );

关于jquery - 如何使用 jquery ui 创建自定义控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9235607/

相关文章:

javascript - 再次绑定(bind)点击按钮的排序功能

javascript - Bootply.com js 片段下载时缺少库

android - Nexus 7 处理 jQuery Mobile : input type number problems

javascript - 在以下情况下,如何让 Waypoints(Jquery 插件)为无限滚动工作?

javascript - 使用 jQuery Validate 的 invalidHandler 事件

javascript - 为什么 jquery 中的 event.target 不起作用

javascript - 使用 serializeArray() 访问自定义属性

javascript - 优化/改进客户端代码

jquery - 为什么 JQuery UI 自动完成样式减号 (-) 在选项中不正确

jquery-ui - jQuery - 输入掩码插件