如何从表中删除这个符号₹

how to remove this symbol ₹ from table

本文关键字:符号 删除      更新时间:2023-09-26

我有这个₹符号,我想删除它,这样我就可以用这个符号导出我的表导出是给出错误

我正在尝试这样做

$(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>

您需要删除印度卢比符号

的unicode字符
str.replace(/[^'x00-'x7F]/g, "");

上面的代码删除字符串中的所有unicode字符。应该可以。

或者只删除符号

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

应该

您可以通过选择td元素并向text()方法提供一个函数来实现这一点,该函数从当前值中删除字符。还请注意,您需要使用一个Regex,并将全局参数设置为删除字符的所有实例,而不仅仅是第一个实例。试试这个:

$(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>

字符串没有被引用,所以您需要在table中再次分配替换更改。

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

但是#replace只会替换这个字符串的第一次出现。替换所有出现的字符串的一个简单方法是将它们在这个字符串中拆分,然后将每个拆分的部分连接起来:

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

我不知道这样做的完整目的是什么,虽然。根据你的能力,有更好的解决方案。