首页 > 代码库 > 给对象添加事件

给对象添加事件

<!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>

 

给对象添加事件