How to get < span> value?

前端 未结 7 2082
温柔的废话
温柔的废话 2021-02-07 10:41

There are a piece of code,but can not use tag.

So,how do I get to the 1 2 3 4?

7条回答
  •  醉酒成梦
    2021-02-07 11:30

    var test = document.getElementById( 'test' );
    
    // To get the text only, you can use "textContent"
    console.log( test.textContent ); // "1 2 3 4"
    

    textContent is the standard way. innerText is the property to use for legacy IE. If you want something as cross browser as possible, recursively use nodeValue.

提交回复
热议问题