_tag.find(‘p’).html(_html);
} else {
_html = ‘<div class=”dropdown ‘ + css + ‘”>’;
_html += ‘<span><font _id=”‘ + default_data.id + ‘”>’ + default_data.name + ‘</font><a></a></span>’;
_html += ‘<p>’;
if (list) {
$.each(list, function (i, value) {
_html += ‘<a _id=”‘ + value.id + ‘”>’ + value.name + ‘</a>’;
});
}
_html += ‘</p>’;
_html += ‘</div>’;
var parent = _tag.parent();
_tag.replaceWith(_html);
_tag = parent.find(‘.dropdown’ + (css.length > 0 ? ‘.’ + css.replace(‘ ‘, ‘.’) : ”));
}
}
//下拉事件
this.showEvent = function () {
_tag.find(‘span’).unbind(‘click’).click(function () {
var p = $(this).parent().find(‘p’);
if (p.css(‘display’) == ‘block’) {
p.css(‘display’, ‘none’);
$(this).removeClass(‘active’);
} else if (p.html().length > 0) {
p.css(‘display’, ‘block’);
$(this).addClass(‘active’);
}
});
}
//选中事件
this.selectedIndex = function (index) {
_tag.find(‘p a’).unbind(‘click’).click(function () {
var parent = $(this).parent().parent();
//给下拉框赋值
if ($(this).text().length > 0) {
var font = parent.find(‘font’);
font.text($(this).text());
font.attr(“_id”, $(this).attr(‘_id’));
_this.selectedIndexExpand(parent, $(this).index());
parent.find(‘span’).removeClass(‘active’);
}
parent.find(‘p’).css(‘display’, ‘none’);
});
if (_tag.find(‘p a’).length <= _index) _index = 0;
if (_value && _value != ”) {
_index = _tag.find(‘p a[_id=”‘ + _value + ‘”]’).index();
}
_tag.find(‘p a:eq(‘ + _index + ‘)’).click();
}
//选中事件扩展
this.selectedIndexExpand = function (tag, index) { }
}
2、示例代码:
//http://www.naoqiu.com
var array_state = [{ id: -1, name: ‘状态’ }, { id: 1, name: ‘未成功’ }, { id: 2, name: ‘成功’ }, { id: 3, name: ‘失败’}];
//状态下拉控件
var select_type = new ComboBox();
select_type.tag = $(‘.select_type’);
select_type.data_default = array_state[0];
select_type.data_list = array_state;
select_type.selectedIndexExpand = function (tag, index) {
//fun_Pager();
}
select_type.init();
3、示例图:










