1. 程式人生 > >給對象添加事件

給對象添加事件

set pre text function ack 事件 pan val har

<!doctype html>
<html lang="en">
<head>
<title>javascript1</title>
<meta charset="utf-8"/>
</head>
<body>
<div>
<label >請輸入您所在城市:</label>
<button id="button">確認填寫</button>
<input type="text" id="incity"/>
<p>您所在的城市是:</
p><p id="pcity"></p> </div> <script type="text/javascript"> (function(){ var output=document.getElementById("pcity"); var input=document.getElementById("incity"); document.getElementById("button").addEventListener(click,function(){ output.innerHTML=input.value;}); })(); </
script> </body> </html>

給對象添加事件