在页面加载时隐藏按钮

时间:2012-08-22 20:39:34

标签: javascript css

在不使用jQuery的情况下,当访问者访问页面时,我希望我的按钮文本"Process"不可见(在所有浏览器中)。当他们从下拉列表中选择一个值而不是first entry (blank)Have a Baby时,可以使按钮可见。

<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>

1 个答案:

答案 0 :(得分:6)

尝试将style="visibility:hidden;"属性添加到按钮。另外,请考虑使用display:nonedisplay:inline-block代替visibility