很多以前的聊天室程序哦,只用到两个文件哦.下我看第一个html文件吧.
<html><head><title>asp简单聊天室程序</title>
<style>*{font:9pt 宋体;line-height:1.7}</style>
<script>
var XmlDom = document.createElement("xml");
XmlDom.onreadystatechange=function()
{
if(XmlDom.readyState == "interactive")
{
var ChatInfo = XmlDom.selectNodes("//聊天");
for(var C=0;C<ChatInfo.length;C++)
{
var From = ChatInfo[C].selectSingleNode("发送人");
var To = ChatInfo[C].selectSingleNode("接收人");
var Say = ChatInfo[C].selectSingleNode("说话");
var Div = document.createElement("div");
Div.appendChild(Text(From.text, From.getAttribute("颜色"), true));
Div.appendChild(Text("对"));
Div.appendChild(Text(To.text, To.getAttribute("颜色"), true));
Div.appendChild(Text("说:"));
Div.appendChild(Text(Say.text, Say.getAttribute("颜色")));
var ShiJian = Text(" [" + (new Date(parseInt(ChatInfo[C].getAttribute("时间"),10))).toLocaleString() + "]", "#abcdef");
ShiJian.style.fontSize = "3mm";
Div.appendChild(ShiJian);
document.body.firstChild.appendChild(Div);
Div.scrollIntoView();
}
setTimeout("Show()", 2000);
}
}
function Text(text, color, clicked)
{
var txtNode = document.createTextNode(text);
if(color)
{
var fontNode = document.createElement("font");
fontNode.color=color;
if(clicked)
{
fontNode.style.textDecoration = "underline";
fontNode.style.cursor = "pointer";
fontNode.onclick = function()
{
document.getElementById("ToName").value = text;
document.getElementById("ChatInput").focus();
}
}
fontNode.appendChild(txtNode);
}
return color?fontNode:txtNode
}
function Show()
{
var SendText;
var MyInput = document.getElementById("ChatInput");
if(MyInput.disabled)
{
var From = document.getElementById("MyName").value;
if(!From) From = "匿名";
var To = document.getElementById("ToName").value;
if(!To) To = "大家";
var FromColor = document.getElementById("MyColor").value;
var ToColor = document.getElementById("SendColor").value;
var ChatColor = document.getElementById("SayColor").value;
SendText = "?" + escape([From,FromColor,To,ToColor,document.getElementById("ChatInput").value,ChatColor].join("b"));
MyInput.disabled = 0;
MyInput.value = "";
MyInput.focus();
}
XmlDom.load("Post.asp" + (SendText?SendText:""));
}
function SetColor(colorId)
{
var clrSel = document.getElementById(colorId);
clrSel.options.selectedIndex = parseInt(Math.random() * clrSel.options.length);
}
onload = function()
{
SetColor("MyColor");
SetColor("SayColor");
SetColor("SendColor");
if(!name) name = prompt("请输入您的名字:","匿名");
document.getElementById("MyName").value = name?name:"匿名";
document.getElementById("ChatInput").focus();
Show();
}
</script>
</head><body><div style="overflow:auto"></div>
<input id="MyName" size="10" value="我"><select id="MyColor">
<option value="#000000" style="background-color:black;color:white">#000000</option>
<option value="#ff0000" style="background-color:#ff0000">#ff0000</option>
<option value="#008000" style="background-color:#008000">#008000</option>
<option value="#0000ff" style="background-color:#0000ff">#0000ff</option>
<option value="#800080" style="background-color:#800080">#800080</option>
<option value="#008080" style="background-color:#008080">#008080</option>
<option value="#808000" style="background-color:#808000">#808000</option>
</select> 对 <input id="ToName" size="10" value="大家"><select id="SendColor">
<option value="#000000" style="background-color:black;color:white">#000000</option>
<option value="#ff0000" style="background-color:#ff0000">#ff0000</option>
<option value="#008000" style="background-color:#008000">#008000</option>
<option value="#0000ff" style="background-color:#0000ff">#0000ff</option>
<option value="#800080" style="background-color:#800080">#800080</option>
<option value="#008080" style="background-color:#008080">#008080</option>
<option value="#808000" style="background-color:#808000">#808000</option>
</select> 说:<select id="SayColor">
<option value="#000000" style="background-color:black;color:white">#000000</option>
<option value="#ff0000" style="background-color:#ff0000">#ff0000</option>
<option value="#008000" style="background-color:#008000">#008000</option>
<option value="#0000ff" style="background-color:#0000ff">#0000ff</option>
<option value="#800080" style="background-color:#800080">#800080</option>
<option value="#008080" style="background-color:#008080">#008080</option>
<option value="#808000" style="background-color:#808000">#808000</option>
</select>
<input style="width:100%" onkeypress="if(value&&event.keyCode==13)disabled=1" id="ChatInput"></body></html>