function refresh_chat()
{
var roomid= " <%=roomid() %> ";
var name= " <%=uname1() %> ";
var one= " <%=getdata1() %> ";
var newmsg =chatclass.getmsg(roomid,name).value;
if(newmsg!= " " && newmsg!= null)
{
if(one !=name ¦ ¦ document.all( "ispub ").checked==false)
{
chat_pub.innerHTML +=newmsg;
}
else
{
chat_sec.innerHTML +=newmsg;
}
}
else
{
chat_pub.innerHTML += " ";
}
window.setTimeout(refresh_chat(),1000);
} Window.setInterval("refresh_chat();",1000)
最好使用document.getElementById("chat_pub")
这句根本没有任何用处
chat_pub.innerHTML += "";
顺便问个问题就结帖了
我想实时读取数据库,因为我做的是聊天室。。
要怎么写sql语句实时更新聊天信息并显示出来。。string sql="select msgid,u_name1,u_name2,msg,roomid,act,ispub,sendtime,face,lastinfo from chat_sendmsg,chatinfo where msgid>'" + last + "' and roomid='" + roomid + "' and ((ispub='false') or (u_name1='" + name1 + "') or (u_name2='" + name1 + "') or (u_name2='所有人'))";
我是这么写的。但是都只能读出自己发的消息。。别人发的消息就是显示不出来。
这句话只是为了显示当刷新时在数据库里读不出东西的时候,不要让它读出null
var roomid="<%=roomid()%>";
var name="<%=uname1()%>";
var one="<%=getdata1()%>";
var newmsg=chatclass.getmsg(roomid,name).value;
if(newmsg!=""&&newmsg!=null){
if(one!=name||document.all("ispub").checked==false){chat_pub.insertAdjacentHTML("beforeEnd",newmsg);}
else{chat_sec.insertAdjacentHTML("beforeEnd",newmsg);}
}
else{chat_pub.insertAdjacentHTML("beforeEnd","");}
window.setTimeout("refresh_chat()",1000);
}
这样子写吗?我知道我写的代码不规范的。。