使用this关键字
this代表当前标签的对象。
<input type="text" onblur="alert(this.value)" />
其他方式
案例一:点击按钮,获取文本框的value,在页面中显示。
案例二:点击按钮,将第一个文本框的值赋值到第二个文本框当中。
<body>
<script type="text/javascript">
window.onload = function(){
document.getElementById("btn").onclick = function(){
alert(document.getElementById("username").value)
}
document.getElementById("btn2").onclick = function(){
document.getElementById("username2").value = document.getElementById("username1").value
}
}
</script>
<input type="text" id="username" />
<input type="button" value="获取文本框中的value" id="btn"/>
<hr />
<input type="text" id="username1" />
<br />
<input type="text" id="username2"/>
<input type="button" value="将第一个文本框的值获取到第二个文本框中" id="btn2" />