【问题标题】:Do Firefox 37 and IE9 support any kind of word break style?Firefox 37 和 IE9 是否支持任何类型的分词样式?
【发布时间】:2015-05-25 14:47:16
【问题描述】:

Firefox 37 和 IE9 是否支持任何类型的分词样式?我尝试了很多,但没有一个工作,它们只在 Chrome 中工作。我试图让这个词在选择中工作,在选项上。另外,show()hide() 在 IE9 上不起作用,也许有人知道为什么?这是我目前的项目:

<!DOCTYPE html>
<html>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <!-- none of these styles work on ff or ie9... -->
    <style>
        select {
            word-break: break-word;
            -ms-word-break: break-word;
            word-break: break-word;
            word-wrap: break-word;
            -webkit-hyphens: auto;
            -moz-hyphens: auto;
            display: inline-block;
            white-space: pre-wrap;
            white-space: -moz-pre-wrap;
            white-space: -pre-wrap;
            white-space: -o-pre-wrap;
            word-wrap: break-word;
            -ms-word-break: break-all;
        }
    </style>
    <head>
        <title>Site Title</title>
    </head>

    <body>
        <h1 style="margin-left:100px;">My List Box Source Example</h1>
        <!-- In style, "word-wrap:break-word" makes items appear over multiple lines if needed, works only on chrome, ff and ie9 broken -->
        <select name="sometext" multiple="multiple" style="width:200px; height:250px; resize:none; margin-left:100px; word-break: break-word;" id="mylist">
            <option value="1">VeryLongText123456VeryLongText123456VeryLongText123456VeryLongText123456VeryLongText123456VeryLongText123456END</option>
            <option value="3">Text1</option>
            <option value="5">Text2</option>
            <option value="6">Text3</option>
            <option value="7">Text4</option>
            <option value="9">Text5</option>
            <option value="12">abc6</option>
            <option value="14">SomeRandomText</option>
            <option value="45">ghi8</option>
            <option value="16">jkl9</option>
            <option value="11">zzz</option>
            <option value="32">xxx</option>
            <option value="73">LastItemHere</option>
        </select>
        
        <h2 style="margin-left:100px;">Search field</h2>
        <textarea rows="2" cols="45" style="margin-left:100px; resize:none; overflow-y:hidden;" id="searchfield"></textarea><br /><br />
        <input id="FilterButton" type="submit" style="margin-left:200px; width: 125px" value="Filter List" class="radius button"/><br /><br />
 
        <script src="jquery-2.1.1.js"></script>
        <script type="text/javascript">
            // Titles - when mouse over entry
            options = document.getElementById("mylist").getElementsByTagName("option");

            for (var i = 0; i < options.length; i++) {
                options[i].title = options[i].text;
            }
            
            $("#FilterButton").click(function () {
                //Show and hide works on chrome and ff, ie9 broken
                var searchText = $("#searchfield").val();
                var list = document.getElementById("mylist");
                for (var c = 0; c < list.length; c++) {
                    if(searchText != null && searchText != '') {
                        var index = list[c].text.toLowerCase().indexOf(searchText.toLowerCase());
                        if(index >= 0) {
                            $('#mylist option[value=' + list[c].value + ']').show();
                        }
                        else {
                            $('#mylist option[value=' + list[c].value + ']').hide();
                        }
                    }
                    else {
                        $('#mylist option[value=' + list[c].value + ']').show();
                    }
                }
            });
    </body>
 </html>

【问题讨论】:

    标签: javascript html css internet-explorer firefox


    【解决方案1】:

    根据 MDN,从 FF 15 和 IE 5.5 开始支持分词

    https://developer.mozilla.org/it/docs/Web/CSS/word-break

    不过,您也应该指定 HTML lang 属性(即&lt;html lang="en"&gt;)。而且 AFAIK 它适用于词汇表,因此您的示例不太可能起作用。

    【讨论】:

    • 嗯,它适用于 chrome,但 ff 和 ie 不支持在 html 选择中分词。正如您在我的示例中看到的那样,select 中的第一项(选项)很长,chrome 可以正确显示多行,但 ff 和 ie9 不支持太多功能...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2016-01-05
    相关资源
    最近更新 更多