根据该(get使用JavaScript )链接下光标一个字我可以根据鼠标pointer.it的细字的英语。 我改变它(阿拉伯语语言)
according this (get a word under cursor using JavaScript )link i can get word under mouse pointer.it's fine for english language. i change it (for arabic language)
<p>سلام به همه</p>
Word: <span id="word"></span>
<script type="text/javascript">
$(function() {
// wrap words in spans
$('p').each(function() {
var $this = $(this);
$this.html($this.text().replace(/[^x00-x80]+/g, "<span>$1</span>"));
});
// bind to each span
$('p span').hover(
function() { $('#word').text($(this).css('background-color','#ffff66').text()); },
function() { $('#word').text(''); $(this).css('background-color',''); }
);
});
但它返回$ 1的每一个字。 请大家帮忙!
but it return '$1' for each word. please help!
推荐答案
您的需要的出现在原来的普通恩pression括号。在常规EX pression符号,括号形式代入了 $ 1
,在替换字符串匹配组。
You need the parentheses that appear in the original regular expression. In regular expression notation, parentheses form a "match group" which is substituted in for the "$1
" in the replace string.
$this.html($this.text().replace(/([^x00-x80]+)/g, "<span>$1</span>"));
没有在你的正则表达式匹配任何团体, $ 1
被简单地视为文字美元符号和一个。
Without any match groups in your regex, the $1
is simply treated as a literal dollar sign and one.
当你有多个括号的匹配组,用于组以取代美元符号,表示编号的占位符的匹配组打开的顺序(第一个匹配组替换 $ 1
,第二替换 $ 2
等)。
When you have multiple parenthesized match groups, the groups are used in to replace dollar-sign-denoted numbered placeholders in the order that the match groups are opened (the first match group replaces $1
, the second replaces $2
, etc).
相关推荐
最新文章