[英]Why does the Underline function in JavaScript not working?
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
is not an accepted value for text-decoration
. text-decoration
不接受normal
值。 Use none
instead. 不使用
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()">
Try this 尝试这个
function underline(){ var text = document.getElementById("note_header").style.textDecoration; if (text == 'none'){ document.getElementById("note_header").style.textDecoration = 'Underline'; } else{ document.getElementById("note_header").style.textDecoration = 'none'; } }
<a href="#" id="note_header" style="text-decoration:none;">This is anchor</a> <input id="btn" type="button" value="Underline" name="btn" onclick="underline()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.