2

我使用的是隱藏的錨無焦點的自舉在這樣的變化中進行選擇:Selectpicker(引導選擇)無焦點的平變化

HTML:

<select id="SelectAddress" name="SelectAddress" class="selectpicker" title="Select an address" data-header="Select an address"> 
    <option id="1" value="1" selected >First address</option> 
    <option id="2" value="2" >Second address</option> 
</select> 

的jQuery:

$("#SelectAddress").on("change", function() { 
//...mycode... 
    $("#AFocus").focus(); 
}); 

$("#AFocus").focus();使選擇選擇器不重點,但它也使頁面上升。 AFocus在頁面頂部,所以...

如何在不使用像我的AFocus這樣的錨標籤的情況下不選中焦點而不滾動頁面?

下面是一個示例:http://jsfiddle.net/ya0o7hzb/向下滾動頁面以查看引導選擇。

回答

2

引導選將在DOM這樣添加一些HTML:

<div class="btn-group bootstrap-select"><button type="button" class="btn dropdown-toggle btn-default" data-toggle="dropdown" role="button" data-id="SelectAddress" title="Address 1" aria-expanded="false"><span class="filter-option pull-left">Address 1</span>&nbsp;<span class="bs-caret"><span class="caret"></span></span></button><div class="dropdown-menu open" role="combobox" style="padding-top: 0px; max-height: 297px; overflow: hidden; min-height: 37px;"><div class="popover-title"><button type="button" class="close" aria-hidden="true">×</button>Select an address</div><ul class="dropdown-menu inner" role="listbox" aria-expanded="false" style="max-height: 248px; overflow-y: auto; min-height: 0px;"><li data-original-index="1" class="selected"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="true"><span class="text">Address 1</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li><li data-original-index="2" class=""><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">Address 2</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li></ul></div><select id="SelectAddress" name="SelectAddress" class="selectpicker" title="Select an address" data-header="Select an address" onchange="blur_picker('SelectAddress')" tabindex="-98"><option class="bs-title-option" value="">Select an address</option> 

所以,你必須blur()包含類BTN按鈕:

$(".btn").blur(); 

工作例如:http://jsfiddle.net/93ohvn0j/

1

試試這個。這可能會訣竅。

<select id="SelectAddress" name="SelectAddress" class="selectpicker" title="Select an address" data-header="Select an address" onChange="blur_picker('SelectAddress')"> 
<option id="1" value="1" selected >First address</option> 
<option id="2" value="2" >Second address</option> 

function blur_picker (element) { 
element = document.getElementById(element); 
element.blur; 
    } 

希望這有助於!

+0

不幸的是'.blur'不適用於selectpicker。 –

+0

下面是一個例子:http://jsfiddle.net/ya0o7hzb/ –