我的html代码在jsfiddle中运行.. 以下是链接:jsfiddle
但是当试图在桌面版本中获得跟踪错误
时未捕获的TypeError:无法读取null的属性“addEventListener” 在six.php:8 (匿名)@ six.php:8
Html:
<html>
<title>capacity utilization factor</title>
<body>
<form method="post">
CUF PERFORMANCE
<div id="wrapper">
<select id="select" name="options">
<option>Select The Value</option>
<option id="hourly" value="a">Hourly</option>
<option id="daily" value="b">Daily</option>
<option id="monthly" value="c">Monthly</option>
<option id="yearly" value="d">Yearly</option>
</select> /div>
</form>
</body>
</html>
JS:
var select = document.getElementById('select');
var wrappElement = document.getElementById('wrapper');
select.addEventListener('change', function() {
if (select.value == 'a') {
var dateElement = document.createElement('input');
dateElement.type = 'dateTime';
wrappElement.appendChild(dateElement);
var dateElement = document.createElement('input');
dateElement.type = 'dateTime';
wrappElement.appendChild(dateElement);
}
}, false);