2016-11-14 48 views
0

我有這個₹符號我想刪除它,這樣我可以在我的表導出帶有此標誌的出口是給錯誤這樣如何刪除這個符號₹從表

我想要的東西

$(document).ready(function(){ 
 
    var table = $('#a').html(); 
 
    table.replace("₹",''); 
 
    console.log(table); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<div id="a"> 
 
<table id="table"> 
 

 
    <tr> 
 
    <th>vcajasjhhjd</th> 
 
    <th>jdshbdfhfdh</th> 
 
    </tr> 
 
    <tr> 
 
    <td>abcd ₹ njdhjdrhjr</td> 
 
    <td>jdhjhjfhjghghg₹jdshdfhs₹</td> 
 
    </tr> 
 

 
</table> 
 

 
</div>

回答

1

您需要刪除印度盧比標誌

str.replace(/[^\x00-\x7F]/g, ""); 

上面的代碼刪除所有的Unicode字符串中的字符的Unicode字符。它應該工作。

或者只刪除ruppees簽署

str.replace("\u20b9",''); 

應該工作

2

可以通過選擇td元件和所述text()方法從除去字符提供的功能實現這一 當前值。另外請注意,您需要使用全局參數設置爲正則表達式的所有實例都將被刪除,而不僅僅是第一個。試試這個:

$(document).ready(function() { 
 
    $('td').text(function(i, t) { 
 
    return t.replace(/₹/g, ''); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<div id="a"> 
 
    <table id="table"> 
 
    <tr> 
 
     <th>vcajasjhhjd</th> 
 
     <th>jdshbdfhfdh</th> 
 
    </tr> 
 
    <tr> 
 
     <td>abcd ₹ njdhjdrhjr</td> 
 
     <td>jdhjhjfhjghghg₹jdshdfhs₹</td> 
 
    </tr> 
 
    </table> 
 
</div>

+0

控制檯不來是空白的,你可以解決它 –

+1

我沒放的console.log代碼,因爲它是多餘的 - 你可以在DOM中看到輸出 –

1

字符串沒有被引用,那麼你需要重新分配在table替換變化。

table = table.replace("\u20b9",''); 

然而#replace只會替換該字符串的第一次出現。更換所有出現一個簡短的方法是通過在此字符串分裂他們,然後加入各劈裂部分:

table = table.split('\u20b9').join(); 

我不知道什麼是這樣做的完全客觀的,雖然。根據你的力量,有更好的解決方案。