美好的一天,
我试图编写这个简单的插件,以便在单击单元格时突出显示表格行:
(function ($) {
$.fn.rowHighlighter = function (options) {
// Establish our default settings
options = $.extend({
text: 'Hello, World!',
color: null,
fontStyle: null,
tableClass: null, // tableClass = '.cardNumbers', columnValue = 'cardNo'
columnValue: null,
rows: null
}, options);
return this.each(function () {
console.log('Inside rowHighlighter plugin...');
$(this).on('click', '#excelTable tr', function (e) {
$('#excelTable tr').removeClass('highlighted-cell');
$(this).addClass('highlighted-cell');
});
});
};
})(jQuery);
代码本身在插件外部工作。我已经确认css有效。
我有一个生成的表,但是主表标签:
<table id="excelTable">
</table>
我用表格注册插件:
$(function() {
$('#excelTable').rowHighlighter();
});