如何在HTML选项中包装文本 [英] How to Wrap Text in HTML Option

查看:95
本文介绍了如何在HTML选项中包装文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的页面上放置一个下拉列表,因为一个选项太长,当我点击选择菜单时,它将展开并覆盖页面的其他部分。

I want to put a dropdown list on my page, As one option is too long, when I click the select menu, it will expand and cover the other part of the page.

<select id="selectlist" name="SelectProgram">

    <option value="LIR" >LIR</option>
        <option value="How to word wrap text in HTML?">How to word wrap text in HTML? CSS / HTML text wrap for webkit</option>

第二个选项太长,会展开。有没有什么办法可以把这么长的文本换成两行?
谢谢!

The second option is too long and will expand. Is there any way I could wrap such a long text into 2 lines? Thank you!

推荐答案

看到Select的值和文本可能会非常不同。我会说如果在你选择的文本中的字符串比X截断长。

Seeing as the value and text of a Select can be very different. I would say if in the event a string thats in your select for the text is longer than X truncate it.

jquery示例

$('#myselect option').each(function()
{
    var myStr = $(this).text();
    if(myStr.length > 15){$(this).text(myStr.substring(15));}
});

将其放入文档中,然后将文本修剪为更好的大小,在div中隐藏溢出的元素会在后来造成一些混乱,并且你会回到这里试图解决由于字符串较小而导致的类似问题。

put that in your document ready, and it will trim your text down to a better size, wrapping your elements in a div that will hide the overflow is going to make something of a mess later, and you will be back here trying to solve a similar issue caused by that for strings that are smaller.

这篇关于如何在HTML选项中包装文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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