Javascript 使按钮在页面加载时隐藏
如果不使用jQuery,我希望当访问者访问页面时,我的文本处理按钮在所有浏览器中都不可见。当他们从下拉列表中选择一个值,而不是第一个输入的空白值,或者有一个婴儿使按钮可见时Javascript 使按钮在页面加载时隐藏,javascript,css,Javascript,Css,如果不使用jQuery,我希望当访问者访问页面时,我的文本处理按钮在所有浏览器中都不可见。当他们从下拉列表中选择一个值,而不是第一个输入的空白值,或者有一个婴儿使按钮可见时 <html> <head> <title>Life Event Picker Calendar</title> <script> // Function being used to hide/unhide the button function changeMess
<html>
<head>
<title>Life Event Picker Calendar</title>
<script>
// Function being used to hide/unhide the button
function changeMessage(oElement) {
if (oElement.value == "100") {
document.getElementById("btn").style.visibility = "hidden";
} else if (oElement.value == "0") {
document.getElementById("btn").style.visibility = "hidden";
} else {
document.getElementById("btn").style.visiblity = "visible";
}
}
</script>
</head>
<body>
...
...
<!-- Based on the selection here - the button below would be made visible -->
<select id="leave" onchange="changeMessage(this);">
<option value="0"></option>
<option value="5">Get Married</option>
<option value="100">Have a Baby</option>
<option value="90">Adopt a Child</option>
<option value="15">Retire</option>
<option value="15">Military Leave</option>
<option value="15">Medical Leave</option>
</select>
<!-- The button in question -->
<button id="btn" onclick="getInfo()"type="button">Process</button>
...
...
</body>
</html>
尝试添加样式=可见性:隐藏;属性添加到按钮。此外,考虑使用显示:没有和显示:内联块而不是可见性。< /P>使用CSS。btn{可见性:隐藏}。通常我会使用display:none,但是因为您使用了可见性,所以我使用了代码。或者:window.onload=function{document.getElementByIdbtn.style.visibility=hidden;};你能把它实现到JSFIDLE中让我看看吗?我真的不明白为什么这个问题被否决了。我想如果有人这样做,人们自然会跟着做。。