0

我有以下 javascript 函数,旨在将 BIDI 代码附加到与特定条件匹配的文本。当前函数的问题是它适用于纯文本内容,但对于具有 HTML 内容的内容存在问题。总而言之,我将文本拆分为单词并检查每个单词中的任何字符是否匹配特定标准以将 BIDI 代码附加到它。

当前状态:

<div>This is the text that I am processing</div> //This works great

<div><span>This is the text</span><p>that I am processing</p></div> // This doesn't work well.

我希望该功能适用​​于文本,但也将包装 HTML 标签保留在其位置以保持

ETC....

function flipper(flipselector) {
        var pagetitle = $(flipselector);
        var text = pagetitle.text().split(' '); //I know that I am using text function here but .html didn't work either
        var newtext="";
    for( var i = 1, len = text.length; i < len; i=i+1 ) {
        //text[i] = '<span>' + text[i] + '</span>';
        newstring="";

        if (matches = text[i].match(/\d/))
        {
            var currentstring=text[i];
            for (var x = 0, charlen = currentstring.length; x < charlen; x++) {

                if (matches = currentstring[x].match(/\d/)) {
                    varnewchar=currentstring[x];
                }else {
                    varnewchar= "&rlm;" + currentstring[x];    
                }

                newstring=newstring + varnewchar;
            }

        } else {
            newstring= text[i];
        }

          newtext=newtext + " " + newstring;
    }
    pagetitle.html(newtext);
    }
4

0 回答 0