<script src="jquery.js"></script>
<script>
var listenedObjs = {}; //被监听的对象
var timers = {}; //监听定时器
function listen(id){ //监听指定元素
listenedObjs[id]=$("#"+id).val();
timers[id] = setInterval("changedEvent('"+id+"')",100);
}
function changedEvent(id){
if($("#"+id).val() != listenedObjs[id]){
listenedObjs[id] = $("#"+id).val();
alert(listenedObjs[id]);
}
}
$(function(){
if(!-[1,]){//IE浏览器使用propertychange监听
$("#testInput").bind("propertychange", function(){
alert($(this).val());
});
}else{//其他浏览器注册监听
listen("testInput");
}
})
function changeTextValue(){
$('#testInput').val(new Date());
}
</script>
<div id="msg"></div>
<input id="testInput" size="35"/>
<input type="button" value="点击改变文本框的值" οnclick="changeTextValue();"/>