excel下拉框实现复选 select实现多选下拉框功能( 三 )


// save pre selected current – if we click on option, or press enter, or press space this is going to be the index of the current option
this.preSelCurrent = dir === ‘next’ ? tmpcurrent + 1 : tmpcurrent – 1;
// remove focus class if any..
this._removeFocus();
// add class focus – track which option we are navigating
classie.add( this.selOpts[this.preSelCurrent], ‘cs-focus’ );
}
}
/**
* open/close select
* when opened show the default placeholder if any
*/
SelectFx.prototype._toggleSelect = function() {
// remove focus class if any..
this._removeFocus();
if( this._isOpen() ) {
if( this.current !== -1 ) {
// update placeholder text
this.selPlaceholder.textContent = this.selOpts[ this.current ].textContent;
}
classie.remove( this.selEl, ‘cs-active’ );
}
else {
if( this.hasDefaultPlaceholder && this.options.stickyPlaceholder ) {
// everytime we open we wanna see the default placeholder text
this.selPlaceholder.textContent = this.selectedOpt.textContent;
}
classie.add( this.selEl, ‘cs-active’ );
}
}
/**
* change option – the new value is set
*/
SelectFx.prototype._changeOption = function() {
// if pre selected current (if we navigate with the keyboard)…
if( typeof this.preSelCurrent != ‘undefined’ && this.preSelCurrent !== -1 ) {
this.current = this.preSelCurrent;
this.preSelCurrent = -1;
}
// current option
var opt = this.selOpts[ this.current ];
// update current selected value
this.selPlaceholder.textContent = opt.textContent;
// change native select element′s value
this.el.value = https://www.520longzhigu.com/diannao/opt.getAttribute( ‘data-value’ );
// remove class cs-selected from old selected option and add it to current selected option
var oldOpt = this.selEl.querySelector( ‘li.cs-selected’ );
if( oldOpt ) {
classie.remove( oldOpt, ‘cs-selected’ );
}
classie.add( opt, ‘cs-selected’ );
// if there′s a link defined
if( opt.getAttribute( ‘data-link’ ) ) {
// open in new tab?
if( this.options.newTab ) {
window.open( opt.getAttribute( ‘data-link’ ), ‘_blank’ );
}
else {
window.location = opt.getAttribute( ‘data-link’ );
}
}
// callback
this.options.onChange( this.el.value );
}
/**
* returns true if select element is opened
*/
SelectFx.prototype._isOpen = function(opt) {
return classie.has( this.selEl, ‘cs-active’ );
}
/**
* removes the focus class from the option
*/
SelectFx.prototype._removeFocus = function(opt) {
var focusEl = this.selEl.querySelector( ‘li.cs-focus’ )
if( focusEl ) {
classie.remove( focusEl, ‘cs-focus’ );
}
}
/**
* add to global namespace
*/
window.SelectFx = SelectFx;
} )( window );


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: