Selecting parenthesis in Arabic text

混江龙づ霸主 提交于 2019-12-24 10:42:29

问题


I copied some Arabic text and pasted it on my website. Now I want to select the parentheses in this Arabic text : http://jsfiddle.net/t6Kdc/

<span>
    كهيعص ﴿١﴾
</span>

jQuery(function () {    
    var oldHtml = jQuery('span').html();
    var newHtml = oldHtml.replace("(","<span style='color: red'>﴾</span>");
    jQuery('span').html(newHtml);
});

For some reason though, there's no way I can select them. Why ?


回答1:


Those are not regular parenthesis, those are parenthesis from Arabic script in Unicode. They are represented as:

U+FD3E ﴾ arabic ornate left parenthesis
U+FD3F ﴿ arabic ornate right parenthesis

(You can see the actual Unicode character rendering at Arabic script in Unicode on Wikipedia)

To replace them in jQuery, you can do the following:

var newHtml = oldHtml.replace("\ufd3e","<span style='color: red'>(</span>"); (replace left parenthesis)

var newHtml = oldHtml.replace("\ufd3f","<span style='color: red'>)</span>"); (replace right parenthesis)




回答2:


You can use html's function, note that the character that you want to be replaced is not (, it's .

jQuery('span').html(function(i, old){
    return old.replace("﴾", "<span style='color: red'>﴾</span>");
});

http://jsfiddle.net/kDWuE/



来源:https://stackoverflow.com/questions/12917472/selecting-parenthesis-in-arabic-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!