无标题文档
<script> <br />
var chat = { <br />
init:function(){ <br />
chat.first(); <br />
$('#chat_btn').unbind('click').click(function(){ <br />
chat.send(); <br />
}); <br />
$('#my_chat').keyup(function(){ <br />
if(event.keyCode == 13){ <br />
chat.send(); <br />
} <br />
});<br />
}, <br />
first:function(){ <br />
$.getJSON('data.php',{ <br />
action:'first', <br />
type:'l' <br />
},function(data){ <br />
chat.btn_status._true(); <br />
$('#mwebtime').html(data.time); <br />
$('#chat textarea').val(data.chat); <br />
$('#chat textarea').stop(true,true).animate({scrollTop:9999}, 1); <br />
chat.socket(); <br />
}); <br />
}, <br />
send:function(){ <br />
chat.btn_status._false(); <br />
$.getJSON('send.php',{ <br />
txt:$('#my_chat').val(), <br />
type:'l' <br />
},function(data){ <br />
if(data.status==200){ <br />
chat.btn_status._false(); <br />
$('#my_chat').val(''); <br />
setTimeout(function(){ <br />
chat.btn_status._true(); <br />
},2000); <br />
} <br />
}); <br />
}, <br />
socket:function(){ <br />
$.getJSON('data.php',{ <br />
action:'while', <br />
type:'l' <br />
},function(data){ <br />
$('#mwebtime').html(data.time); <br />
$('#chat textarea').val(data.chat); <br />
$('#chat textarea').stop(true,true).animate({scrollTop:9999}, 1); <br />
chat.socket(); <br />
}); <br />
}, <br />
btn_status:{ <br />
_false:function(){ <br />
$('#chat_btn').html('等待').attr('disabled',true); <br />
}, <br />
_true:function(){ <br />
$('#chat_btn').html('发言').attr('disabled',false); <br />
} <br />
} <br />
} <br />
chat.init(); <br />
</script>