2
我試圖將懸停功能添加到jQuery小部件。這是我的,但它不起作用。我錯過了什麼?我所希望做的是擴大標題的長標題將自定義懸停功能添加到jQuery小部件
我把它的jsfiddle http://jsfiddle.net/7JHXt/
(function ($) {
$.widget('nt.textline', {
options: {
title: { short: 'XXX', long: 'XXXXXXXXXXXX'},
text: 'Some text'
},
widgetEventPrefix: 'textline:',
_create: function() {
this.element.addClass('textline');
// chart container
this._container = $('<div class="textline-container"></div>')
.appendTo(this.element);
this._setOptions({
title: this.options.title,
text: this.options.text
});
},
_destroy: function() {
this.element.removeClass('textline');
this.element.empty();
this._super();
},
_setOption: function (key, value) {
var self = this,
prev = this.options[key],
fnMap = {
'title': function() {
createTitle(value, self);
},
'text': function() {
createText(value, self);
}
};
// base
this._super(key, value);
if (key in fnMap) {
fnMap[key]();
// Fire event
this._triggerOptionChanged(key, prev, value);
}
},
_triggerOptionChanged: function (optionKey, previousValue, currentValue) {
this._trigger('setOption', {type: 'setOption'}, {
option: optionKey,
previous: previousValue,
current: currentValue
});
},
_hoverable: function() {
alert('here')
e.css({"background-color":"red"});
}
});
function createTitle(title, widget) {
// Clear existing
widget._container.find('.title').remove();
var t = $('<div class="title"></div>')
.text(title.short);
widget._container.append(t);
}
function createText(text, widget) {
// Clear existing
widget._container.find('.text').remove();
var t = $('<div class="text"></div>')
.text(text);
widget._container.append(t);
}
})(jQuery);
$('.textline').textline({});
你不能只是粘貼你的所有代碼,並期望我們找出它的錯誤,解釋你想要完成的事情,告訴我們它是如何失敗的,你是否在瀏覽器的控制檯中發現錯誤?如果你給我們提供一個例子來測試代碼,那麼它總是更可取的,在[jsfiddle](http://jsfiddle.net)也許是 –
是一個好主意。我在上面 – KeepCalmAndCarryOn