我希望我的名字与#34; fn_warn"单击提交时可见。
我的html和js代码是,
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
First name
<input id="first_name" type="text"/>
<p id="fn_warn" style=" visibility: hidden; color: red;">#Please enter a valid name...</p>
<input class="button" onclick="tada();" type="submit" value="Submit" /> <input class="button" type="reset" />
</body>
</html>
<script>
function tada(){
var x= document.getElementById("fn_warn");
x.setAttribute("visibility","visible");
}
</script>
答案 0 :(得分:1)
CSS规则不是属性。请使用style
属性,因为规则是内联的:
function tada(){
var x = document.getElementById("fn_warn");
x.style.visibility = "visible";
}