首页 > 解决方案 > I want option text break or equal to select width?

问题描述

codepenlink

How to break line of option text and equal to select tag width.

标签: htmlcssbootstrap-4

解决方案


您不能将格式应用于此答案中提到的选项下拉列表

但是,您可以使用省略号之类的东西。

var maxLength = 15;
$('#example > option').text(function(i, text) {
    if (text.length > maxLength) {
        return text.substr(0, maxLength) + '...';  
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="example" id="example">
    <option value="">This is some long text</option>
    <option value="">Short Text</option>
    <option value="">This is some really, really long text</option>
</select>


推荐阅读