如何关闭“selectOptions”?现在我只能在单击“span.selected”或“span.selectArrow”时关闭它。我想在点击其他列表时关闭它,或者只是列出清单。
function enableSelectBoxes(){
$('div.selectBox').each(function(){
$(this).children('span.selected').html($(this).children('div.selectOptions').children('span.selectOption:first').html());
$(this).attr('value',$(this).children('div.selectOptions').children('span.selectOption:first').attr('value'));
$(this).children('span.selected,span.selectArrow').click(function(){
if($(this).parent().children('div.selectOptions').css('display') == 'none'){
$(this).parent().children('div.selectOptions').css('display','block');
}
else
{
$(this).parent().children('div.selectOptions').css('display','none');
}
});
$(this).find('span.selectOption').click(function(){
$(this).parent().css('display','none');
$(this).closest('div.selectBox').attr('value',$(this).attr('value'));
$(this).parent().siblings('span.selected').html($(this).html());
});
});
}
答案 0 :(得分:0)
你可以这样做:
$(document).click(function(event) {
//If the user clicks somewhere on the page, but not on the autocomplete.
if(event.target != $("#autocomplete")[0]) {
$("#autocomplete").hide();
}
});