我想使用 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/