html - I want option text break or equal to select width?
解决方案
您不能将格式应用于此答案中提到的选项下拉列表
但是,您可以使用省略号之类的东西。
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>
推荐阅读
- ros - 不同帧率的 ROS 主题同步
- php - 为什么在 laravel 5.6 中从表单发送数据时会出现 401 错误?
- javascript - 如果为空,如何将值附加到输入或使用 ajax 添加带有值的逗号?
- javascript - 下拉占位符分隔符
- unity3d - 用于跨服务器和客户端同步变量的 RPC 和命令调用或网络消息?
- python - TypeError: unhashable type: 'numpy.ndarray' mnist
- google-cloud-platform - gcloud cloudshell ssh 不断退出 gcloud
- c - 文本文件的最后一行打印两次
- html - Bootstrap 3 具有相同高度和宽度的卡片 CSS HTML
- vb.net - 如何在 VB 表单中截取完整的屏幕截图