gpt4 book ai didi

JQuery ui selectmenu 占位符不起作用

转载 作者:行者123 更新时间:2023-12-01 07:45:21 26 4
gpt4 key购买 nike

我添加了 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'
});

错误是文本未定义。我使用的是 Jquery UI 版本 1.12.0

最佳答案

而不是:

this.buttonText.text( placeholder );  

尝试:

this.buttonItem.text(placeholder);

buttonText确实存在:您只有按钮和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>

关于JQuery ui selectmenu 占位符不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39271419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com