Подтвердить что ты не робот

Как удалить первый символ из текста ссылки с помощью jQuery?

Я хочу удалить первый символ из текста ссылки с помощью jQuery.

<span class="test1"> +123.23 </span>
<span class="test2"> -13.23 </span>

Я хочу удалить "+" и "-" из jQuery.

Вывод:

<span class="test1"> 123.23 </span>
<span class="test2"> 13.23 </span>
4b9b3361

Ответ 1

var val = $("span").html();
$("span").html(val.substring(1, val.length));

Ответ 2

$("span.test1, span.test2").each(function() {
  $(this).text($(this).text().replace(/[+-]/, ""));
});

Ответ 3

// 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

Ответ 4

вы можете получить/установить HTML с помощью .html() и удалить первый символ с помощью .substring(), я думаю, теперь это довольно ясно, вам просто нужно написать код из 2 (или 3) строк.