在Javascipt中顺序删除字符串中的所有字符

每次Java事件(单击按钮)时,我都希望删除字符串中的字符。

例如:

str = "world";

单词在每个步骤中都会发生如下变化:

  • “世界”
  • “ rld”
  • “ ld”
  • “ d”
  • “”
yanchenghua2009 回答:在Javascipt中顺序删除字符串中的所有字符

您可以使用String.slice(N)从字符串中删除前N个字符

您可以做什么:

<button id="my_button">WORLD</button>
document.querySelector("#my_button").addEventListener('click',function() {
    this.innerText = this.innerText.slice(1)
});  
,

您可以使用此功能

function deleteString(value){
   return value.substring(1);
} 
str = deleteString(str)
本文链接:https://www.f2er.com/3132103.html

大家都在问