2.2 点击按钮改变文本框中的文字内容
功能:点击第一个按钮生成文字,第二个按钮清除文字
事件:onclick
属性:input的value
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="css1.css" rel="stylesheet" type="text/css"
charset="UTF-8">
</head>
<body>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="改文字"/>
<input id="btn2" type="button" value="清空文字"/>
<script src="js1.js"> </script>
</body>
</html>
/////////////////js
var oBtn1=document.getElementById("btn1");
var oBtn2=document.getElementById("btn2");
oBtn1.onclick=function(){
var oTxt=document.getElementById("txt1");
oTxt.value="good!";
};
oBtn2.onclick=function(){
var oTxt=document.getElementById("txt1");
oTxt.value="";
};