我面臨事件添加事件監聽器功能的問題它不會給出錯誤,它只是不工作我甚至聽過視頻複製和粘貼其他代碼工作和修改我的HTML工作,但它添加事件偵聽器不會在這裏工作是我的代碼波紋管添加事件監聽器
<!DOCTYPE html>
<html>
<head><title>Main page of a simple website</title>
<link rel="stylesheet" type="text/css" href="mstn.css"/>
<link href='https://fonts.googleapis.com/css?family=Josefin+Slab:100' rel='stylesheet' type='text/css'>
</head>
<body>
<header>
<a href="https://www.google.com" target="_parent">click here to go to google</a>
<a href="victimclient.rar" download="victimclient.rar">here</a>
<p id="demo">testing testing testing </p>
<p>testing testing testing</p>
<h1>whats little g</h1>
<script type="text/javascript" src="checkthisout.js">
y = document.getElementById("input").addEventListener("click", myFunction);
if(y){
function myFunction() {
alert("hello world")
}
}
</script>
<input holder="password" value="replace here" id="input"/>
</body>
爲什麼把函數定義放入if條件中?這不是必需的。當添加事件偵聽器時,需要定義**函數,否則不會發生任何事情。 – evolutionxbox