首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用jQuery删除链接文本中的第一个字符?

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

Stack Overflow用户
提问于 2009-11-06 09:57:47
回答 4查看 57K关注 0票数 15

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

代码语言:javascript
运行
复制
<span class="test1"> +123.23 </span>
<span class="test2"> -13.23 </span>

我想从with jQuery中删除"+“和"-”。

输出:

代码语言:javascript
运行
复制
<span class="test1"> 123.23 </span>
<span class="test2"> 13.23 </span>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2009-11-06 10:02:09

代码语言:javascript
运行
复制
var val = $("span").html();
$("span").html(val.substring(1, val.length));
票数 40
EN

Stack Overflow用户

发布于 2009-11-06 10:02:12

代码语言:javascript
运行
复制
$("span.test1, span.test2").each(function() {
  $(this).text($(this).text().replace(/[+-]/, ""));
});
票数 25
EN

Stack Overflow用户

发布于 2009-11-06 10:02:46

代码语言:javascript
运行
复制
// 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
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1684939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档