文本框失去焦点事件原来可以在html里面直接写,但是因为是动态生成文本框,所以要在后面绑定。直接使用js绑定,一直无法有效。
var updateTime=function(){
alert(this.value);
}
document.getElementById('time').onblur =updateTime;
无论如何都不会执行,换成jquery代码:
$j("#time").blur(function(){
alert(123);
});
也无法实现,后来发现要在js里面为文本框绑定事件必须要将代码写到window.onload事件里面:
var updateTime=function(){
alert(this.value);
}
document.getElementById('time').onblur =updateTime;
}
$j(document).ready(function(){
$j("#time").blur(function(){
alert(123);
});
});
也执行成功