存档

‘Javascript’ 分类的存档

感谢小秦帮我指出错误:
  JSON只是一种数据形式,而不是你所谓的当然。
{xx:’111′}  这是一个对象,这个对象有一个属性名为 xx 值为 ’111′
而不是JSON。
还有那个Create,也只是变相的使用函数返回一个对象而已。
从根本上来讲,创建一个对象可以使用 new _object_,或者 {}  ,
“{}”这种形式其实是new _object_的简写。
就像 [] 是 new Array();的缩写一样。
更何况,在JS里一切都是对象。
比如:
1
 就是一个对象,它有 .toString方法,等等。。
      前几天写了一篇揭开Javascript对象神秘的面纱,结果网上一位牛人转载了我的文章,我的还没收录,他转载的竟然先被收录了,无语。在此鄙视百度。
      本来事情该告一段落了,但是论坛上有位网友告诉我说只测试function的方法成功了,其他都不行。汗,今晚抽点空,写几个例子,下载地址为:http://www.miaoqiyuan.cn/products/js-obj.rar
第一种:function方式,用new fun_name的方式创建对象

function miaoqiyuan() {
this.name="苗启源";
this.nickname="飞猫,mqycn";
this.homeurl=function() {
alert("http://www.miaoqiyuan.cn");
};
this.gohome=function() {
location.href="http://www.miaoqiyuan.cn";
}
}
var x=new miaoqiyuan;
x.homeurl();

第二种:直接创建对象的方式

var miaoqiyuan={
name:"苗启源",
nickname:"飞猫,mqycn",
homeurl: function() {
alert("http://www.miaoqiyuan.cn");
},
gohome: function() {
location.href="http://www.miaoqiyuan.cn";
}
};
miaoqiyuan.homeurl();

第三种:原型方式(这个我写了两个方式)

var miaoqiyuan = {};
miaoqiyuan.prototype=miaoqiyuan;
miaoqiyuan.prototype.name ="苗启源";
miaoqiyuan.prototype.nickname ="mqycn,飞猫";
miaoqiyuan.prototype.homeurl = function() {
alert("http://www.miaoqiyuan.cn");
};
miaoqiyuan.prototype.gohome= function() {
location.href="http://www.miaoqiyuan.cn";
};
miaoqiyuan.homeurl();

<script type="text/javascript">
var miaoqiyuan = {};
miaoqiyuan.prototype=miaoqiyuan;
miaoqiyuan.prototype={
name:"苗启源";
nickname:"mqycn,飞猫";
homeurl:function() {
alert("http://www.miaoqiyuan.cn");
};
gohome:function() {
location.href="http://www.miaoqiyuan.cn";
};
}
miaoqiyuan.homeurl();
</script>

第四种:create方式,该方式利用了Prototype JavaScript组件库,很少见有人用
实际上这个只是变相的使用函数返回一个对象而已。

//模拟prototype.js框架中的Class
var Class = {create: function() {return function(){}}}
//模拟prototype.js框架中的Object
Object.extend=function(destination, source){
for(var property in source)
destination[property] = source[property];
return destination;
};
 
var miaoqiyuan [...]

十二 17th, 2008 | Filed under Javascript, Life(生活)

朋友手中有上千个域名,现在cn域名续费涨价了,准备抛弃一些。让我帮忙写个小程序来筛选一下,看看那个有留下的价值。当时我放出大话,20分钟搞定。最初设想的是生成Excel文件,通过Excel中的筛选来统计。
代码如下(附件包中的excel.vbs):

‘域名统计程序,生成excel结果
‘通过VBS获取当前目录,替代ASP中的Server.Mappath
Function Mappath(v)
Mappath=fso.getAbsolutePathName(v)
End Function
 
‘写得一个函数,用于判断字符串中是否含有数字。
Function iszajiao(v)
for i=1 to len(v)
if isnumeric(mid(v,i,1)) then
iszajiao=1
exit for
end if
next
End Function
 
‘创建一个FSO对象
Set fso=CreateObject("Scripting.FileSystemObject")
 
‘判断是否有生成的Excel结果ok.xls,如果有,则删除
if fso.fileexists(mappath("ok.xls")) then fso.getfile(mappath("ok.xls")).delete
 
‘创建一个ok.xls
set fto=fso.createtextfile(mappath("ok.xls"),2)
wscript.echo "吴哥哥,请稍等,我正在为您工作中。。。"
fto.writeline "域名 后缀 位数 类型"
 
‘寻找当前目录中的所有txt文件,如果有则依次打开
for each file in fso.getfolder(mappath(".")).files
if Lcase(fso.getExtensionName(file))="txt" then
set db=fso.opentextfile(file,1)
 
‘如果不是在txt文件的结尾,则循环读取
do while not db.atendofstream
rs=db.readline
 
‘获取域名的位数,即第一次出现.的位置-1
ws=cint(instr(rs,".")-1)
 
‘防止本行数据为空行
if ws>=1 then
rsi=rsi+1
 
‘获取域名
ym=left(rs,ws)
 
‘获取域名后缀
hz=replace(rs,ym&".","")
 
‘分析域名类型,如果ym为数字则为数字
if isnumeric(ym) then
lx="数字"
‘否则,如果出现数字则为杂交
elseif iszajiao(ym)=1 then
lx="杂交"
‘其他类型就剩下字母了
else
lx="字母"
end if
‘输出
fto.writeline ym&" "&hz&" "&ws&" "&lx
end if
loop
end if
next
fto.close
set fto=nothing
msgbox "吴哥哥,我帮你完成工作了,怎么谢我呢?请我吃MM吧"

正准备邀功请赏的时候,朋友竟然说没用过Excel,狂吐血,并且还不想用数据库。这儿就有点复杂了,初步设想生成HTML文件,然后把数据保存到数组中,根据Select的选项来现在最终结果。
我是从两个方便考虑的,生成网页部分由Javascript控制,这些Javascript最终代码由VBScript来生成。
[...]

十二 9th, 2008 | Filed under Div+CSS, Javascript, VBscript
标签: ,

演示地址:http://www.miaoqiyuan.cn/map.htm

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>QiyuanMap</title>
<script type="text/javascript" src="http://union.mapbar.com/apis/maps/free?f=mapi&v=31
&k=aCW9cItqL78uTR0saSg8TR5pT75hMYF9OIJhMHTsMRWhMYcyZYf9TnT=@STZh8yT=7h05pZYM75sp78hM7hyWhMyqTYLZJHY8fy7f@5JMnhR78JCYHMTaMS@HMMaFAr="></script>
<script type="text/javascript">
var maplet = null;
function initMap(){
maplet = new Maplet("mapbar");
maplet.centerAndZoom(new MPoint(118.2848,35.09736), 10);
maplet.addControl(new MStandardControl());
 
//标注信息
var marker = new MMarker(
new MPoint(118.2848,35.09736),
new MIcon("http://www.miaoqiyuan.cn/favicon.ico",32,32)
);
//添加标注
maplet.addOverlay(marker);
}
</script>
</head>
 
<body onload="initMap()" style="padding:0px;margin:0px;">
<div id="mapbar" style="width:382px;height:340px"></div>
<script type="text/javascript">
//让地图全屏显示
document.getElementById("mapbar").style.height=document.body.clientHeight+"px";
document.getElementById("mapbar").style.width=document.body.clientWidth+"px";
</script>
</body>
</html>

十二 2nd, 2008 | Filed under Javascript
标签: , ,

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>FileList with VBScript&Javascript</title>
<script type="text/vbscript">
on error resume next
 
Function Mappath(v)
Mappath=fso.getAbsolutePathName(v)
End Function
 
Function getPath(style,path)
pathlist="<select style=""float:left;"&style&""" ondblclick=""javascript:FileMan(this.value)"">"
if path="" or not fso.folderexists(path) then
pathlist=pathlist+"<option value="""">我的电脑</option>"
for each xx in fso.drives
pathlist=pathlist&"<option value="""&xx&""">"&xx&"\</option>"
next
else
set fpo=fso.getfolder(path)
‘pathlist=pathlist&"<option value="""&path&""">当前目录==>"&path&"</option>"
if len(path)>3 then
pathlist=pathlist&"<option value="""&fpo.parentfolder&""">..</option>"
else
pathlist=pathlist&"<option value="""">我的电脑</option>"
end if
for each xx in fpo.subfolders
if i=0 then x=" selected" else x=""
i=1
pathlist=pathlist&"<option value="""&xx&""" title="""&xx&""""&x&">"&xx&"</option>"
next
pathlist=pathlist&"</select><select style=""float:left;"&style&""" ondblclick=""javascript:openFile(this.value);"">"
for each xx in fpo.files
if i=0 then x=" [...]

十二 1st, 2008 | Filed under Javascript, VBscript

随着业务量的增多,客户信息管理又是一个问题,而且客户的资料、画册已经堆积如山了,找一个客户的资料太难了,于是我想到了给客户信息编号,如9月21日跑来的就是9.21-1,9.21-2,把客户在本站的文件名,密码都记录下来。。。噩梦又出现了,今天客户改这,明天改那,记事本已将化的不成样子了
为何不用简单的网站来管理呢?在网上找OA系统?这个太大材小用了吧~因为自己本身就是程序员,还是自己写个吧~
下载地址:http://www.miaoqiyuan.cn/products/sitemanger.rar
通过本程序,可以方便的列出需要拍照的,需要传图的,没有简介的,需要客户确认的,已经完成的单子的信息~
大大的放百年了我们的管理,值得一提的(我最自豪的)是直接点击公司名称即可选中(边框为蓝色),再点取消,通过点击上边的“修改为..”可以批量修改选中的Case的状态(隐藏了checkbox,点击设checkbox设为Ture),不是通过ID来修改,项目可以为任意多,而且可以通过全选,反选来快速选择。
运用了CSS+Javascript+ASP(VBScript),在workeasy系类中我最喜欢的一个工具。

十 2nd, 2008 | Filed under ASP, Div+CSS, Javascript, Share(分享), Show(展示)

分析了下临沂批发市场网(CNLY888.COM)的休闲娱乐模块,发现了一个很有意思FlashAPI,叫FlashAPI不是很确切,应该是Flash引用的API
调用方法有两种:
1.两次握手,实现Flash API的调用(推荐)
a.本地服务器,通过程序提供的API接口,并将需要的信息保存到本地数据库,并将操作交给API提供商的程序处理
http://img-cnly888.union.myw3.cn/r/Happy/Game-API?Play=1001/SWF&Swf_Name=MJ/DEMO/&Page=/Play.asp
b.远程服务器,将需要的内容保存到API提供商的数据库,并返回到API使用者的调用页面
http://flash.union.myw3.cn/Game/Playing.Html?Play=mj&Url=http://www.cnly888.com/Game.html&Page=Play.html
c.本地服务器,返回到API使用者的调用页面,调用最终显示的内容
http://www.cnly888.com/Game.html?Play=mj
d.远程服务器,通过框架引用API页面的内容
http://flash.union.myw3.cn/game/playing.html?Play=mj
2.一次握手法,直接引用Flash API页面
a.本地服务器,API使用者的调用页面,调用最终显示的内容
http://www.cnly888.com/Game.html?Play=mj
b.远程服务器,通过框架引用API页面的内容
http://flash.union.myw3.cn/game/playing.html?Play=mj
具体思想,还是先从简单的第二种方法入手。
既然是一个API程序,如果直接能访问那就没有什么意思了~
http://flash.union.myw3.cn/game/playing.html?Play=mj
这个页面的代码很简单,一个简单的静态页面

<script type="text/javascript" src="myw3sys.js"></script>
<script type="text/javascript">
if(top.location==self.location){
var __X=_Query("Url");
if(__X)
location.href=__X+"?Play="+_Query("Play");
else
alert("非法接口");
}else{
_Swf(_Query("Play"));
}
</script>

初学Javascript的朋友可能会说_Swf,_Query是什么东东?只是MyW3Sys.js提供的一个函数,不需要了解,直接用即可
_Swf(Flash文件名,宽,高,是否透明,FlashURI);在页面添加一个Flash,只有文件名是必须的参数
_Query(XXX);返回GET提交的XXX的数据
使用方法可以到MyW3Sys.js简易文档(http://labs.myw3.cn/JS/myw3sys/)页面查询
只有当被框架引用的时候,才调用_Swf函数显示Flash文件,显示那个,_Query()获取的那个,http://flash.union.myw3.cn/game/playing.html?Play=mj就是调用mj.swf打开http://flash.union.myw3.cn/game/myw3sys.js,myw3_res=”Playing”;那么Flash文件的相对路径为playing/mj.swf
如果不是被框架引用,那就是第一种方法的b(远程服务器,将需要的内容保存到API提供商的数据库,并返回到API使用者的调用页面),判断是否通过GET提交了调用程序的URL,没有就无路可走了(o(∩_∩)o…),只好提示错误了。提交了URL则构造URL的查询参数?Play=_Query(“Play”),即?Play=mj,然后跳转到该URL,然后通过本地接口调用

document.writeln("<iframe src=’http://flash.union.myw3.cn/game/playing.html?Play="+_Query(’Play’)+"’ frameborder=0></iframe>");

需要注意的是,别忘了引用MyW3Sys.js哦,否则不能实用_Query();
这个FlashAPI程序还不是很完善,应该是在测试阶段~
我分析了下MyW3Sys.js,并结合本程序,想出了一个自动判断服务器快慢选择最快的服务器的方案
因为已过两网,实在是。。。电信用户调用电信站点的Flash,网通用户调用网通的站点的Flash

<iframe src="ad.html" src="x_flash"></iframe>
<img src="http://dianxin.xxx.com/err.gif" onerror="_load_flash(this)" />
<img src="http://wangtong.xxx.com/err.gif" onerror="_load_flash(this)" />
<script type="text/javascript">
var x_flash=document.getElementById("x_flash")
function _load_flash(o){
if(x_flash.src!="ad.html"){
x_flash.src=o.src.replace("err.gif","")+"flash_api?123456789";
}
}
</script>

九 18th, 2008 | Filed under Javascript
标签: ,