function underline() {
var text = document.getElementById("note_header").style.textDecoration;
if (text == 'normal') {
document.getElementById("note_header").style.textDecoration = 'Underline';
} else {
document.getElementById("note_header").style.textDecoration = 'normal';
}
}
<input id="btn" type="button" value="Underline" name="btn" onclick="underline()">
最佳答案
normal
不是 text-decoration
可接受的值。请改用 none
。
function underline(){
var text = document.getElementById("note_header").style.textDecoration;
if (text !== 'underline'){
document.getElementById("note_header").style.textDecoration = 'underline';
} else{
document.getElementById("note_header").style.textDecoration = 'none';
}
}
<textarea id="note_header" rows="3" cols="15">
That's my note
</textarea><br/>
<input id="btn" type="button" value="Underline" name="btn" onclick="underline()">
关于javascript - 为什么 JavaScript 中的下划线功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55608558/