问题
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