焦点事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>焦点事件</title>
</head>
<body>
<input type="text" name="" placeholder="请输入内容">
<input type="text" name="" >
<input type="text" name="">
<input type="button" name="" value="按钮">
<script type="text/javascript">
var oInput=document.getElementsByTagName('input')[0];
var oInput1=document.getElementsByTagName('input')[1];
oInput.onfocus=function (){
if (this.placeholder=='请输入内容') {
this.placeholder='';
}
}
oInput.onblur=function (){
if (this.value=='') {
this.placeholder='请输入内容';
}
}
</script>
</body>
</html>
焦点方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>焦点方法</title>
</head>
<body>
<input type="text" name="">
<input type="button" name="" value="搜索">
<input type="text" name="">
<input type="button" name="" value="全选">
<div>aaaaaaaaaaaaaa</div>
<script type="text/javascript">
var oInput1=document.getElementsByTagName('input')[0];
var oInput2=document.getElementsByTagName('input')[2];
var oBtn=document.getElementsByTagName('input')[3];
oInput1.focus();
oBtn.onclick=function (){
oInput2.select();
}
</script>
</body>
</html>