JQuery UI Selectmenu заполнитель не работает
Я добавил Jquery UI Selectmenu заполнитель не работает, показывая ошибку
$.widget( 'app.selectmenu', $.ui.selectmenu, {
_drawButton: function() {
this._super();
var selected = this.element
.find( '[selected]' )
.length,
placeholder = this.options.placeholder;
if (!selected && placeholder) {
this.buttonText.text( placeholder );
}
}
});
$('select').selectmenu({
placeholder: 'Select a speed'
});
Ошибка text is not defined
, Я использую Jquery UI версии 1.12.0
1 ответ
Решение
Вместо:
this.buttonText.text( placeholder );
попробуйте с:
this.buttonItem.text(placeholder);
buttonText существует: у вас есть только button и buttonItem, и вам нужен buttonItem для изменения текста.
Пример:
$.widget( 'app.selectmenu', $.ui.selectmenu, {
_drawButton: function() {
this._super();
var selected = this.element
.find( '[selected]' )
.length,
placeholder = this.options.placeholder;
if (!selected && placeholder) {
this.buttonItem.text(placeholder);
}
}
});
$(function () {
$('#speed').selectmenu({ placeholder: 'Select a speed' });
});
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<label for="speed">Select a speed</label>
<select name="speed" id="speed">
<option>Slower</option>
<option>Slow</option>
<option>Medium</option>
<option>Fast</option>
<option>Faster</option>
</select>