jQuery UI Selectmenu占位符不起作用 [英] JQuery ui selectmenu placeholder is not working

查看:83
本文介绍了jQuery UI Selectmenu占位符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经添加了jQuery ui selectmenu占位符,无法显示错误

I had added Jquery ui selectmenu placeholder is not working showing error

$.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

Error is text is not defined. I am using Jquery UI version 1.12.0

推荐答案

而不是:

this.buttonText.text( placeholder );  

尝试:

this.buttonItem.text(placeholder);

buttonText确实存在:您只有button和buttonItem,并且需要buttonItem才能更改文本.

buttonText does exist: you have only button and buttonItem and you need buttonItem to change the text.

示例:

$.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占位符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆