我有一个按钮标签,里面有两个 span;
<button><span><span id="buttonText">Save</span></span></button>
我正在尝试做到这一点,以便当您单击按钮时,文本会发生变化;
onclick="document.getElementById('buttonText').innerHTML = 'Saving...'; this.style.className"
现在很有趣,它在 IE8 中运行良好,但在 Firefox 和 Chrome 中测试时,都失去了我在按钮和 span 上设置的 css 滑动门样式。
最佳答案
不如操纵 nodeValue 怎么样? .firstChild.nodeValue
如果没记错的话。
关于JavaScript innerHTML 导致 css 在 <button> 上消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3652685/