gpt4 book ai didi

javascript - document.getElementById().style.display = 'none' ;仅适用于 Firefox

转载 作者:行者123 更新时间:2023-12-04 02:10:34 24 4
gpt4 key购买 nike

为什么这只适用于 Firefox?IE 和 Chrome 似乎忽略了 style.display = 'none'有什么建议吗?

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>


<script language="JavaScript">
function validateForm() {

document.getElementById('option2').style.display = 'none';

}
</script>

</head>
<body>
<select id="employeeID" onchange="validateForm();">
<option value="0" id="option0">Select an Employee</option>
<option value="1" id="option1">Employee 1</option>
<option value="2" id="option2">Employee 2</option>
<option value="3" id="option3">Employee 3</option>
</select>
</body>
</html>

最佳答案

您应该使用 .addEventListener 方法将 change 事件绑定(bind)到您的选择元素 ->

DEMO

Javascript

function validateForm() {

alert(); //checking if this actually works

document.getElementById('option2').style.display = 'none';

}


select_ = document.getElementById('employeeID');

select_.addEventListener('change',validateForm,false);

select_.onchange = validateForm;

Chrome

Chrome

Safari

Safari

关于javascript - document.getElementById().style.display = 'none' ;仅适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23270475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com