php+js+mysql设计的仿webQQ-<6>JS创建聊天窗口
来源:互联网 发布:外国人在淘宝网可以吗 编辑:程序博客网 时间:2024/05/21 13:58
<11>Js创建聊天窗口
先看一下效果图
所在页面的head中加入以下Js代码来定义全局变量
Js代码
<script type="text/javascript">var count=2,t=50,l=20;</script>
创建聊天窗口的Js代码
function createDialogDiv(obj){ count++; //其中count为全局变量,用来决定层的堆叠顺序 var dialogID="chat"+obj.id;if(document.getElementById(dialogID)){ //检测对话框是否应经存在 alert("对话框已存在!"); }else{var dialogDiv=document.createElement('div'); //创建层dialogDivdocument.body.appendChild(dialogDiv);dialogDiv.id=dialogID; //给层dialogDiv设置属性dialogDiv.style.width='360px';dialogDiv.style.height='320px';dialogDiv.style.background="#006633";dialogDiv.style.position = "absolute";dialogDiv.style.top=t+ "px"; //t和下文的l为全局变量,用来确定层的位置dialogDiv.style.left=l + "px";var titleDiv=document.createElement('div');dialogDiv.appendChild(titleDiv);titleDiv.style.width='360px';titleDiv.style.height='30px';titleDiv.style.color="#FFFFFF";titleDiv.onclick=function(){ //当用鼠标点击该对话框时,该对话框到最上面count++;dialogDiv.style.zIndex=count;}var titleTable=document.createElement("table");titleDiv.appendChild(titleTable);titleTable.style.width="360px";titleTable.style.height="24px";var titleTr=document.createElement("tr");titleTable.appendChild(titleTr);var titleTd1=document.createElement("td");titleTr.appendChild(titleTd1);titleTd1.style.width="30px";var titleTd1Img=document.createElement("img");titleTd1.appendChild(titleTd1Img);titleTd1Img.style.width="24px";titleTd1Img.style.height="24px";titleTd1Img.src="avatar/"+ obj.id +".jpg";var titleTd2=document.createElement("td");titleTr.appendChild(titleTd2);titleTd2.style.width="300px";titleTd2.style.align="left";titleTd2.innerHTML=obj.id;var titleTd3=document.createElement("td");titleTr.appendChild(titleTd3);titleTd3.style.width="20px";var titleTd3Img=document.createElement("img");titleTd3.appendChild(titleTd3Img);titleTd3Img.style.width="16px";titleTd3Img.style.height="16px";titleTd3Img.style.cursor="pointer";titleTd3Img.title="关闭";titleTd3Img.src="chat/close.png";titleTd3Img.onclick=function(){ //当用鼠标点击关闭的图片时,清除创建的层dialogDiv.parentNode.removeChild(dialogDiv);}var chatDivID="to"+obj.id;var chatDiv=document.createElement('div');dialogDiv.appendChild(chatDiv);chatDiv.id=chatDivID;chatDiv.style.width='350px';chatDiv.style.height='180px';chatDiv.style.margin='0 auto';chatDiv.style.background="#FFFFFF";chatDiv.style.color="black";chatDiv.style.overflow="auto";refreshChatDiv(obj,chatDivID); //该js方法用来刷新聊天信息var messageDiv=document.createElement('div');dialogDiv.appendChild(messageDiv);messageDiv.style.width='350px';messageDiv.style.height='100px';messageDiv.style.margin='5px auto';var messageText=document.createElement('textarea');messageDiv.appendChild(messageText);messageTextID="text"+obj.id;messageText.id=messageTextID;messageText.style.width='345px';messageText.style.height='70px';var messageTable=document.createElement("table");messageDiv.appendChild(messageTable);var messageTr=document.createElement("tr");messageTable.appendChild(messageTr);var messageTd1=document.createElement("td");messageTd1.style.width="290px";messageTr.appendChild(messageTd1); var messageTd2=document.createElement("td");messageTr.appendChild(messageTd2);var messageSpan=document.createElement('span');messageTd1.appendChild(messageSpan);messageSpan.style.color="red";var messageButton=document.createElement("input"); messageTd2.appendChild(messageButton);messageButton.type="button";messageButton.style.color="#FFFFFF";messageButton.style.background="#006633";messageButton.style.cursor="pointer";messageButton.value="发送";messageButton.onclick=function(){if(document.getElementById(messageTextID).value==""){messageSpan.innerHTML="不能发送空消息!";}else{messageSpan.innerHTML="";var text=document.getElementById(messageTextID).value;sendMessage(obj,chatDivID,text);document.getElementById(messageTextID).value="";}}var h = document.documentElement.clientHeight - 340;//求浏览器的可见高度if(t<h){t=t+35;l=l+35;}else{t=60;l=50;} }dialogDiv.style.zIndex=count;}
欢迎大家拍砖!(未完待续)
- php+js+mysql设计的仿webQQ-<6>JS创建聊天窗口
- php+js+mysql设计的仿webQQ-<7>聊天消息的发送与刷新
- php+js+mysql设计的仿webQQ-<1>邮箱验证
- php+js+mysql设计的仿webQQ-<2>其他验证
- php+js+mysql设计的仿webQQ-<5>IM窗体的实现
- php+js+mysql设计的仿webQQ-<3>月份天数随月份改变
- php+js+mysql设计的仿webQQ-<4>登陆和注册
- js 调用qq聊天窗口
- 仿webqq的webos框架zos,基于hoorayos2.0移植的纯html+js版本,后端语言.net
- JS+CSS打造可拖动的聊天窗口层
- Ajax+js+dom+json+php+mysql实现仿google的超强分页、隔行变色效果
- ajax+js+dom+json+php+mysql实现仿百度、google的分页效果
- ajax+js+dom+json+php+mysql实现仿百度、google的分页效果
- js创建普通的弹出窗口
- HTML,CSS,JS实现网页聊天窗口
- WebSocket+node.js创建即时通信的Web聊天服务器
- 实现简单的 webQQ聊天系统
- 使用ExtJS+WebSocket实现的WebQQ聊天
- VC 键盘 按键 虚拟码 表
- 在学习中进步
- 数据结构03.1 队列模拟(数组)
- DP算法入门(3)——最大子段和
- 合并排序
- php+js+mysql设计的仿webQQ-<6>JS创建聊天窗口
- 用wsprintf格式化字符串 .
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程 .
- 关于java优先队列的用法
- DirectX9 SDK Samples(16) ShadowMap Sample(1)
- Antenna Impedance
- test
- C++中通过溢出覆盖虚函数指针列表执行代码
- 梦境