我想用jQuery从链接的文本中删除第一个字符。
<span class="test1"> +123.23 </span>
<span class="test2"> -13.23 </span>
我想从with jQuery中删除"+“和"-”。
输出:
<span class="test1"> 123.23 </span>
<span class="test2"> 13.23 </span>
发布于 2009-11-06 10:02:09
var val = $("span").html();
$("span").html(val.substring(1, val.length));
发布于 2009-11-06 10:02:12
$("span.test1, span.test2").each(function() {
$(this).text($(this).text().replace(/[+-]/, ""));
});
发布于 2009-11-06 10:02:46
// 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
https://stackoverflow.com/questions/1684939
复制相似问题