如何使用jQuery从链接的文本中删除第一个字符?

我想用jQuery删除链接文本中的第一个字符。

 +123.23   -13.23  

我想从jQuery中删除“+”和“ – ”。

输出:

  123.23   13.23  

 var val = $("span").html(); $("span").html(val.substring(1, val.length)); 
 $("span.test1, span.test2").each(function() { $(this).text($(this).text().replace(/[+-]/, "")); }); 
 // get the current text text1 = $(".test1").html(); // set the text to the substring starting at the third character $(".test1").html(text1.substring(2)); // extract to the end of the string text2 = $(".test2").html(); $(".test2").html(" " + text2.substring(2)); // looks like you want to keep the leading space 

你可以使用.html()获取/设置HTML并使用.substring()删除第一个字符,我认为现在很清楚,你只需要写一个2(或3)行代码。