<input type="text" id="hj"/>
<script type="text/javascript">
(function(){
hj.onchange=function(){
document.write(hj.value+"222");
}
})();
<script type="text/javascript">
(function(){
hj.onchange=function(){
document.write(hj.value+"222");
}
})();
</script>
文档中每一个ID都会自动创建一个全局变量,所以技术上来说,document.getElementById是可以不写的,
这儿document.write(),会冲刷掉前面的input,这是因为window.onload之后的document.write();都会重刷文档