我需要使用Jquery翻转twitter引导字形。
例如,如果文档是RTL(我在div中检查,不在dir属性中检查)
然后,我将从右向左和从左向右翻转字形。

我尝试了这个:

function rtlChange() {
    var textDirection = $("#mydiv").data("direction");
    if (textDirection == "rtl") {
        $("i.glyphicon.glyphicon-chevron-right").toggleClass('glyphicon-chevron-right glyphicon-chevron-left');
        $("i.glyphicon.glyphicon-chevron-left").toggleClass('glyphicon-chevron-left glyphicon-chevron-right');
         $("i.glyphicon.glyphicon-arrow-right").toggleClass('glyphicon-arrow-right glyphicon-arrow-left');
        $("i.glyphicon.glyphicon-arrow-left").toggleClass('glyphicon-arrow-left glyphicon-arrow-right');
        $("i.glyphicon.glyphicon-hand-right").toggleClass('glyphicon-hand-right glyphicon-hand-left');
        $("i.glyphicon.glyphicon-hand-left").toggleClass('glyphicon-hand-left glyphicon-hand-right');
     }
}


这将“ glyphicon-人字形右”更改为“ glyphicon-人字形左”。但是由于下一行,所有“ glyphicon-雪佛龙左”更改为“ glyphicon-雪佛龙右”。

我需要权利一次又一次地离开。

小提琴:http://jsfiddle.net/mavent/qc88s/19/

这个Jquery怎么做?

最佳答案

您可以像其他人一样以非常简单的方式做到这一点:

function rtlChange() {

    var textDirection = $("#mydiv").data("direction");
    if (textDirection == "rtl") {
        $("i.glyphicon").each(function( index ) {

            if($(this).hasClass("glyphicon-chevron-right")){
                $(this).removeClass("glyphicon-chevron-right");
                $(this).addClass("glyphicon-chevron-left");
            }else{
                $(this).removeClass("glyphicon-chevron-left");
                $(this).addClass("glyphicon-chevron-right");
            }
        });
    }
}


这是小提琴http://jsfiddle.net/qc88s/26/

关于jquery - jQuery翻转RTL的类数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24838861/

10-12 12:50
查看更多