标题:正开始学习JavaScript,请教一问题,搞不明呀。。。。
只看楼主
开心人
Rank: 1
等 级:新手上路
帖 子:216
专家分:0
注 册:2005-11-1
 问题点数:0 回复次数:19 
正开始学习JavaScript,请教一问题,搞不明呀。。。。


近来想学习JavaScript语言,找到了一段显示在线人数的代码OnlineCount.asp,如下:

_______________________________________________________________________________________

<%@ Language=JavaScript %>
<%
var strCountData="1234567890";
var theTime=new Date();

function GetOnline()
{
if (typeof(Application("GuestOnline"))=="undefined")
Application("GuestOnline")="0";
}

function checkGuest()
{
//check Me
if (typeof(Session("test"))=="undefined")
Session("test")="guest";
var strUserName=String(Session("test"));
var strGuestOnline=String(Application("GuestOnline"));
var GuestArray=strGuestOnline.split("\n");
var i;
var iGuestNum;
if (typeof(Session("GuestNum"))=="undefined")
{
for (i=0;i<GuestArray.length;i++)
{
if (GuestArray[i]=="0") break;
}
Session("GuestNum")=i;
}

iGuestNum=Session("GuestNum")*1;
if (iGuestNum>10000)iGuestNum=10000;

var strFormatTime=theTime.getTime();
strFormatTime="0000000000000000000"+strFormatTime;
strFormatTime=strFormatTime.substr(strFormatTime.length-16,16);

GuestArray[iGuestNum]=strFormatTime+strUserName;

strGuestOnline=GuestArray.join("\n");
Application("GuestOnline")=strGuestOnline;

return 1;
}

function GetNumber()
{
//Count Guests on line
var strFormatTime=theTime.getTime()-5*60*1000;
strFormatTime="0000000000000000000"+strFormatTime;
strFormatTime=strFormatTime.substr(strFormatTime.length-16,16);

var strGuestOnline=String(Application("GuestOnline"));
var GuestArray=strGuestOnline.split("\n");

var iGuestCounter=0;
var i;
for (i=0;i<GuestArray.length;i++)
{
if (GuestArray[i].substr(0,16)> strFormatTime)
iGuestCounter++;
else if (GuestArray[i].length>0)
GuestArray[i]="0";
}
strGuestOnline=GuestArray.join("\n");
Application("GuestOnline")=strGuestOnline;
strCountData=iGuestCounter;
return strCountData;
}

function OutPut()
{
var i;
strCountData=""+strCountData;

var strDigits= new Array(
"0","0x3c","0x66","0x66","0x66","0x66","0x66","0x66","0x66","0x66","0x3c", //0
"1","0x30","0x38","0x30","0x30","0x30","0x30","0x30","0x30","0x30","0x30", //1
"2","0x3c","0x66","0x60","0x60","0x30","0x18","0x0c","0x06","0x06","0x7e", //2
"3","0x3c","0x66","0x60","0x60","0x38","0x60","0x60","0x60","0x66","0x3c", //3
"4","0x30","0x30","0x38","0x38","0x34","0x34","0x32","0x7e","0x30","0x78", //4
"5","0x7e","0x06","0x06","0x06","0x3e","0x60","0x60","0x60","0x66","0x3c", //5
"6","0x38","0x0c","0x06","0x06","0x3e","0x66","0x66","0x66","0x66","0x3c", //6
"7","0x7e","0x66","0x60","0x60","0x30","0x30","0x18","0x18","0x0c","0x0c", //7
"8","0x3c","0x66","0x66","0x66","0x3c","0x66","0x66","0x66","0x66","0x3c", //8
"9","0x3c","0x66","0x66","0x66","0x66","0x7c","0x60","0x60","0x30","0x1c"); //9

var iCharCount=strCountData.length;
var iCharWidth=8;
var iCharHeight=10;
var theBit;
var theNum;
Response.ContentType ="image/x-xbitmap";
Response.Expires =0;

Response.Write ("#define counter_width "+ iCharWidth*iCharCount+"\r\n"); //图形宽
Response.Write ("#define counter_height "+ iCharHeight+"\r\n"); //图形高
Response.Write ("static unsigned char counter_bits[]={\r\n");

for (iRow=0;iRow<iCharHeight;iRow++)
for (i=0;i<iCharCount;i++)
{
theBit=strCountData.charAt(i);
for (k=0;k<strDigits.length;k+=(iCharHeight+1))
{
if (strDigits[k]==theBit)break;
}
if (k>=strDigits.length)k=0;
theOffset=k+1;

Response.Write (strDigits[theOffset+iRow]);
Response.Write (",");
}

Response.Write ("};\r\n");

}

GetOnline();
checkGuest();
GetNumber();
OutPut();
%>

________________________________________________________________________________________

这个程序在别的页面上用<img src="OnlineCount.asp">来进行显示,但是奇怪的是:IE浏览的时候显示不出(如图一),而有些朋友的NetScape却能显示正常???



我想也许是解释方面的问题,是不是语句不是很规范?在第一句那里(红色),我看了教材上说的:“JavaScript代码在标识<Script Language ="JavaScript">...</Script>之间就可加入JavaScript脚本。。。。”

于是我对应进行了修改语言标注方法,但是运行时跳出了服务器端调试窗口(没有错误提示),显示也是失败。。。

数据库的在线数据正常呀。。。(如图)

各位高手,是否能扶持一下新学员。。。指点一下呀???



[此贴子已经被作者于2005-11-2 13:59:46编辑过]

搜索更多相关主题的帖子: JavaScript var function Application 
2005-11-02 13:54
linuxpluto
Rank: 4
等 级:贵宾
威 望:13
帖 子:889
专家分:23
注 册:2005-8-14
得分:0 
这是asp问题~~asp的脚本可以用javascript也可以用 vbscript,但一般都用vbscript,你所说的这是个asp文件,文件的脚本语言用的是javascript,javascript在ie和netscape中的对象很多都不一样~~运行在2中浏览器的脚本都是分别写开的~~~

吃的比猪还差,干的比驴还累,起的比鸡还早,睡得比小姐还晚,挣得比民工还少,看起来比谁都好——苦命的人.人生短短几十年,不要给自己留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己
2005-11-02 14:01
开心人
Rank: 1
等 级:新手上路
帖 子:216
专家分:0
注 册:2005-11-1
得分:0 
哦??那是否可以修改呢?

另外,第一句那个红色的句子规范吗?

2005-11-02 14:06
linuxpluto
Rank: 4
等 级:贵宾
威 望:13
帖 子:889
专家分:23
注 册:2005-8-14
得分:0 
是声明~asp中默认的是vbscript,如果不用默认的话 就要这个语句~或者在服务器端修改默认的脚本语言可以不用这句声名

吃的比猪还差,干的比驴还累,起的比鸡还早,睡得比小姐还晚,挣得比民工还少,看起来比谁都好——苦命的人.人生短短几十年,不要给自己留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己
2005-11-02 14:26
开心人
Rank: 1
等 级:新手上路
帖 子:216
专家分:0
注 册:2005-11-1
得分:0 

我知道是声明,我只是想知道这两种声明哪种比较规范。。

1、<%@ Language=JavaScript %>

2、
<Script Language ="JavaScript">...</Script>


2005-11-02 15:28
linuxpluto
Rank: 4
等 级:贵宾
威 望:13
帖 子:889
专家分:23
注 册:2005-8-14
得分:0 

都是规范的~~2个是两码事~~不要混为一谈~~
<%@ Language=JavaScript %>
<%
javascript代码;
就象用asp代码一样,不用<script>框起来了
%>
这是写服务器的程序的,用来写文件
--------------------------------------
<Script Language ="JavaScript">
javascript代码;
</Script>
用来写程序块的,<Script Language ="JavaScript">可以包含在
<%@ Language=JavaScript %>中
例如
<%@ Language=VBScript %>
<Script Language ="JavaScript">
javascript代码;
</Script>
有一种包含和被包含的关系
---------------------------------------
<Script src="xxx.asp">
</Script>
有人这样调用asp,文件,我没试过,不知道能不能用
如果,xxx.asp文件中全是javascript代码是可行的
<Script src="xxx.js">
</Script>
这样是可行的


吃的比猪还差,干的比驴还累,起的比鸡还早,睡得比小姐还晚,挣得比民工还少,看起来比谁都好——苦命的人.人生短短几十年,不要给自己留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己
2005-11-02 15:52
开心人
Rank: 1
等 级:新手上路
帖 子:216
专家分:0
注 册:2005-11-1
得分:0 
哦。。。。。哦。。。。。哦。。。。。原来有这些区别呀,明白了,谢谢版主了。。。

2005-11-02 16:05
开心人
Rank: 1
等 级:新手上路
帖 子:216
专家分:0
注 册:2005-11-1
得分:0 
不过,我记得几个月前在IE是能正常显示的,不知道是否是2000自动升级了什么,就不兼容了,再用IE就看不见了,如果用VB来写一个应该能避免这种问题了吧

2005-11-02 16:24
linuxpluto
Rank: 4
等 级:贵宾
威 望:13
帖 子:889
专家分:23
注 册:2005-8-14
得分:0 

javascript也有版本之分的~~~~


吃的比猪还差,干的比驴还累,起的比鸡还早,睡得比小姐还晚,挣得比民工还少,看起来比谁都好——苦命的人.人生短短几十年,不要给自己留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己
2005-11-02 18:06
linuxpluto
Rank: 4
等 级:贵宾
威 望:13
帖 子:889
专家分:23
注 册:2005-8-14
得分:0 
浏览器的版本,浏览器的类型,脚本的版本不一样的化,可能有一点微妙的变化~~

吃的比猪还差,干的比驴还累,起的比鸡还早,睡得比小姐还晚,挣得比民工还少,看起来比谁都好——苦命的人.人生短短几十年,不要给自己留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己
2005-11-02 18:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-32309-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026823 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved