事件注册方式:
将事件绑定到元素属性;
将事件绑定到对象属性,例如:
<body>
<input type="button" id="btn1" value="按钮1" οnclick="test()"/>
<input type="button" id="btn2" value="按钮2"/>
<script type="text/javascript">
function test(){
alert("aa")
}
document.getElementById("btn2").οnclick=function(){
alert ("bb")
}
window.οnlοad=function(){
console.log("cc")
}
window.οnresize=function(){
console.log ("dd")
}
</script>
</body>
表单元素-文本框
属性:value文本框的内容;readonly只读,只允许后台修改
方法:focus()使文本框获得焦点;select()选中文本框内容
事件:onblur文本框失去焦点时触发;onfocus文本框获得焦点时触发;onchange文本框内容改变且失去焦点时触发
<--利用onblur事件实现文本框中英文字母全部转换成大写-->
<body>
在文本框中输入:<input type="text" name="" id="one" value="" οnblur="test()"/><br>
失去焦点后:<input type="text” name="" id="two" value=""/>
<script type="text/javascript">
function test(){
var a = document.getElementById("one").value
document.getElementById("two").value=a.toUpperCase()
}
</script>
</body>