登錄
1、頁面登陸的基本要素
你可以在我的竹葉看到登陸的表單,這里提供了最基本的登陸表單項
(1)登陸表單
- <form method=POST name=chatform action=chat/login.php?action=enter onSubmit="b1_submit();return true;" target="howtodo">
(a)聊天表單的名字為chatform,我使用action=enter作為進入聊天室的入口,如果沒有這個參數,則顯示登陸頁面.
(b)在表單提交時,先調用b1_submit()建立聊天的窗口
(c)聊天的目標窗口為b1_submit()建立的howtodo窗口
(2)表單項
昵稱:<input type=text name=name size=15 maxlength="10">
密碼:<input type=passWord name=pass size=15 maxlength="10">
<input type=submit name=submit value=登陸 style="width:100">
<input type=reset name=reset value=重添 style="width:50">
(a)各表單項一定要設定最大允許長度 maxlength
(3)建立聊天窗口的js
- <script LANGUAGE="javascript">
- function b1_submit(){
- chat=window.open('',"howtodo",'Status=no,scrollbars=no,resizable=no');
- chat.moveTo(0,0);
- chat.resizeTo(screen.availWidth,screen.availHeight);
- chat.outerWidth=screen.availWidth;
- chat.outerHeight=screen.availHeight;
- }
這段代碼先打開一個沒有狀態欄,滾動條,可調整尺寸的howtodo窗口!然后移動到屏幕左上角,然后放大到允許的屏幕大小.
在線人數
我根據網易聊天室的在線人數的方法,顯示當前的在線人數,代碼解釋如下:
1、登陸時建立在線人名單的數組,放在body后面
- <?
- //鎖定在線人數文件
- while(file_exists($useronlinelock)){$pppp++;}
- fclose(fopen($useronlinelock,"w"));
- //讀入在線人名單
- $useronline = file($useronline);
- unlink($useronlinelock);
- //建立數組 list
- print("document.writeln("list=new Array(");
- $k=count($useronline);
- if($k>1)
- {
- for($i=0;$i<($k-1);$i++)
- {
- $usercurrent = split($split,$useronline[$i],99);
- // 姓名+,
- print("'$usercurrent[0]',");
- }
- $i=$k-1;
- // 處理最后一個姓名
- $usercurrent = split($split,$useronline[$i],99);
- print("'$usercurrent[0]'");
- }
- // 數組結束
- print(")");n");
- ?>
2、顯示在線人數的js
- document.writeln('[在線人數<font color=red>'+count+'</font>]<br>');
- document.writeln("[<a href="Javascript:parent.cs('所有人')">所有人</
- a>]<br>");
- document.writeln("<font class='p9'>");
- var j,name,club;
- for(var i=0;i<list.length;i=i+1)
- {
- if(list[i]!=null){
- //顯示每個在線人的名字
- document.writeln("<a href="javascript:parent.cs('"+list[i]+"')" titl
- e='"+list[i]+"'>"+list[i]+"</a><br>");
- }
- }
- this.r.document.writeln('</font><hr>');
3、改變聊天對象
- function cs(name)
- {
- if(this.d.document==null)return;
- if(name=='所有人')
- {
- this.d.add('所有人');
- this.d.document.inputform.talkto.value='所有人';
- //改變焦點
- this.d.document.inputform.msg.focus();
- return;
- }
- for(var i=0;i<list.length;i=i+1)
- {
- if(list[i]==name)
- {
- //更改發送的談話對象
- this.d.document.inputform.talkto.value=list[i];
- this.d.document.inputform.msg.focus();
- return;
- }
- }
- //錯誤
- alert('此用戶已離線或已改了昵稱。');
- }
新聞熱點
疑難解答