2013-04-20 77 views
0

卢比符号代替美元符号这是我的代码中,我试图用INR使用jQuery(印度卢比),以取代美元符号$,但它不工作,因为这只是一个样本代码,以便它不是ul >lifind textreplace text有点儿东西,我的尝试是这样的 - 我试着先收集整个HTML,然后用代码替换$标志,但是它没有做出任何反应。查找和使用jQuery

我的假设 - 在$(document).ready()使用$(this)这个片段中引用文档,让我知道如果这是一个错误的假设,因为我想我试图保持这种事情记在心里。

DO NOT给任何链接/转诊做到在CSS方式或Webrupee API的使用,保持它的简单jQuery的这段时间:)

我的代码 -

<!DOCTYPE html> 
<html> 
<head> 
    <title>Rupee Change - jQuery Flavour</title> 
</head> 

<body> 
<p>This is a price listing with &#36; sign, Now I wanted to replace each dollar sign with rupee symbol</p> 
<ul> 
<li>&#36; 500</li> 
<li>&#36; 600</li> 
<li>&#36; 700</li> 
<li>&#36; 800</li> 
<li>&#36; 900</li> 
</ul> 

<div id="showhtml"></div> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$(this).html().replace("$", "<del>&#2352;</del>"); 
}); 
</script> 
</body> 
</html> 

仅供参考 - 我也尝试过这种处理方式但不工作:(find-text-string-using-jquery

+1

你需要重新分配回的HTML。 $(本)的.html($(本)。html的()代替( “$”, “”)); – 2013-04-20 12:30:04

+0

@ParthikGosar不工作:( – swapnesh 2013-04-20 12:33:16

回答

3

$是正则表达式中的一个特殊字符,您需要将其转义出来

$(document).ready(function(){ 
    var replaced = $('body').html().replace(/\$/g, "<del>&#2352;</del>"); 
    $('body').html(replaced); 
}); 
+1

感谢让我清楚有关REGEX的用法:) +1 – swapnesh 2013-04-20 12:43:44

+0

这对我有帮助,但出于某种原因,我不得不用两个斜线使它与美元符号一起工作,如下所示:replace(/\\ $ /克, “”); – 2017-04-10 20:53:16