下面的代码工作正常,但它没有在Firefox上
在firefox中未定义事件对象。那么在这种情况下如何获取对事件对象的引用
<html>
<body>
<p>Click the button to display the date.</p>
<button onclick="displayDate()">The time is?</button>
<script>
function displayDate(e) {
if (!e) var e = window.event;
alert(e.target.innerText);
document.getElementById("demo").innerHTML = Date();
}
</script>
<p id="demo"></p>
</body>
</html>
感谢您的帮助
答案 0 :(得分:1)
对于Firefox,您必须将事件传递给函数:
<button onclick="displayDate(event)">The time is?</button>
<script>
function displayDate(e) {
document.getElementById("demo").innerHTML = Date();
}
</script>