虽然涉及更多一些,但您可以将选项转换为显示的 div(而不是选择),然后处理显示的 div 元素上的单击事件:
$('body').on('click', 'form > div', function (e) {
var self = $(this),
options = self.find('select option'),
div = $('<div />'),
select = div.clone().addClass('pop-up-selector');
$('.pop-up-selector').remove();
options.each(function (i, elem) {
var opt = $(elem);
select.append(div.clone().data('value', opt.val()).text(opt.text()));
});
console.log(true);
select.appendTo(self);
});
$('body').on('click', '.pop-up-selector > div', function (e) {
var self = $(this),
val = self.data('value'),
text = self.text(),
overlabel = self.parent().siblings('.overlabel');
// display to user and store value for later
overlabel.find('.fakeinput').data('value', val).text(text);
// select corresponding option in select element in case you're using that later
overlabel.find('select option').each(function (i, elem) {
var opt = $(elem),
selected = opt.val() === val;
opt.attr('selected', selected);
});
window.setTimeout(function () {
$('.pop-up-selector').remove();
}, 0);
});
和一些基本的 CSS,所以它看起来更好一点:
.pop-up-selector {
background-color: #FFF;
}
.pop-up-selector > div:hover {
background-color: #CCC;
}
工作演示:http: //jsfiddle.net/QAAYd/5/