<codeclass="language-html"><script>
function myFunction(){
var x=document.getElementById("fname");
x.value=x.value.toUpperCase();
}
</script><body>
输入你的名字: <input type="text" id="fname" onchange="myFunction()"><p>当你离开输入框后,将小写字母转为大写字母。</p></body>
函数不同,产生效果不同,
<codeclass="language-html"><html><head><script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script></head><body>
Enter your name: <input type="text" id="fname" onchange="upperCase(this.id)"></body></html>