2013-04-20 79 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