0

JS のいくつかの選択オプションに css クラスを設定しています。このクラスにはマージン スタイルが含まれます。FF では動作しますが、IE と chrome では動作しません。

 window.onload = function() {
    replace('edit-field-region-tid');
    replace('edit-tid');
}
function replace(id) {
    var i = 0;
    var s = document.getElementById(id);
    for (i; i < s.options.length; i++) {
        if (find(s.options[i].text, id, i)) {
            s.options[i].setAttribute("class", "sub_options");
        }
    }
}
function find(str, id, option_id) {
    var i;
    var s = document.getElementById(id);
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == '-') {
            s.options[option_id].text = str.cutAt(0, "");
            return true;
        }
    }
    return false;
}
String.prototype.cutAt = function(index, char) {
        return this.substr(index+1, this.length);
}

そしてCSS:

.sub_options{
    margin-left:20px;
    text-indent:-2px;
}

どんなアイデアでもありがとう!

ファイアフォックス

クロム

4

1 に答える 1

1

この方法で行うことができます: http://jsbin.com/oyatis/1/edit

$('select option').prepend('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');

jquery の css メソッドを使用してみましたが、影響はありませんが、要素を移動する有効な方法として改行しないスペースがいくつかあります。これがうまくいくかどうかを確認してください。

于 2012-11-16T10:58:22.437 に答える