存档
这个函数我觉得还是比较实用的,用于69dns.com的一个新项目。代码有点熟悉?不过这个可是我原创的代码哦。
还有一个控制xml,控制form,控制css,以及加载的boot.js。
当然还有很多东西都不完善,等以后有空的时候,都整理一下。
实际上只是创建了一个stcms的json对象。为了能独立使用加入了if(typeof(stcms)==”undefined”)stcms={};,算是另类的命名空间吧。
/*
文件:ajax.js
挂载:stcms
独立:可独立使用
设计:猫七@69dns.com
*/
(function(){
if(typeof(stcms)==”undefined”)stcms={};
stcms.ajaxstatus=0;
stcms.ajax=function(url,str,method,callback){
if(stcms.ajaxstatus==1){
alert(“请等待上一个进程处理完。”);
return;
}
if(url.indexOf(“?”)!=-1)url+=”&sendTme=”+new Date();else url+=”?sendTme=”+new Date();
var xmlhttpRequest;
if(typeof(xmlhttpRequest!=”object”)){
if(window.ActiveXObject){
try{
xmlhttpRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
}catch(e){
xmlhttpRequest = false;
}
}else if(window.XMLHttpRequest){
xmlhttpRequest = new XMLHttpRequest();
}
}
if(xmlhttpRequest){
stcms.ajaxstatus=1;
xmlhttpRequest.open(method,url,true);
if(method==”post”)xmlhttpRequest.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”);
xmlhttpRequest.setRequestHeader(“charset”,”gb2312″);
xmlhttpRequest.onreadystatechange=function(){
if(xmlhttpRequest.readyState==4){
if(xmlhttpRequest.status==200){
callback(xmlhttpRequest.responseText);
stcms.ajaxstatus=0;
}
}
};
xmlhttpRequest.send(str);
}
}
})();
使用方法很简单:
stcms.ajax(‘a.asp’,null,’get’,function(t){alert(t)});
很简单吧。另外发一下我boot.js,我觉得还是比较实用的;
/*
文件:boot.js
挂载:root
功能:加载js
设计:猫七@69dns.com
*/
(function(skin){
var i,ie,d;
stcms={
listen:function(f){
var l;
window.onload=(typeof(l=window.onload)!=’function’)?f:function(){l();f();};
},
$:function(id){
return document.getElementById(id);
}
};
ie=!!((d=(document)).all);
(function(arr){
for(i in arr){
var o=d.createElement(“script”);
o.setAttribute(“type”,”text/javascript”);
o.setAttribute(“src”,arr[i].replace(“stcms.”,”js/”).replace(/\./g,”\/”).replace(“*”,”all”)+”.js”)
d.getElementsByTagName(‘head’)[0].appendChild(o);
}
})([
'stcms.common.client.mouse',
'stcms.common.client.keyboard',
'stcms.skin.'+skin,
'stcms.common.form.form',
'stcms.common.form.grid',
'stcms.common.form.box',
'stcms.common.ajax',
'stcms.common.xml',
'stcms.common.cookie',
'stcms.user.checklogin',
'stcms.control.init'
]);
})(‘default’);
现在boot.js已经实现了皮肤,listen(实际就是window.onload),加载js,通过id获取dom等四个功能。
其他的可能就不太常用的,吧所有的都细分,这样可以减少请求和文件大小哦。
’stcms.common.ajax’,就是上边的ajax.js。
如果有时间,我也准备写个js框剪,集合了所有的功能,哈哈哈。
Test
Test
/*
文件名:set-Object.html
设计者:苗启源
功 能:可以方便的给DOM对象添加方法,可支持所有浏览器
主 页:http://www.miaoqiyuan.cn/p/set-Object
*/
var $=function(id){return document.getElementById(id);}
//SetObject 设置对象属性
var setObject=function(c,d){for(p in d){c[p]=d[p];if(p==”init”)c.init();}return c;}
//扩展属性
var __isIE=function(){return window.ActiveXObject}
var __Name=function(t){if(this.tmp)this.name=this.tmp;else this.name=’Hello’}
var __setClass=function(t){if(__isIE){this.className=t}else{this.setAttribute(‘class’,t);}}
var __getClass=function(){if(__isIE){return this.className}else{return this.getAttribute(‘class’);}}
//测试对象
var ob=$(“Demo”);var ob2=$(“Demo2″);
setObject(ob,{tmp:’Demo’,init:__Name,setClass:__setClass,getClass:__getClass});
setObject(ob2,{init:__Name,setClass:__setClass,getClass:__getClass});
document.write(ob.name+”\n”);
document.write(ob2.name+”\n”);
document.write(ob.getClass()+”\n”);
document.write(ob2.getClass()+”\n”);
ob.setClass(‘newDemoClass’);
ob2.setClass(‘newDemo2Class’);
document.write(ob.getClass()+”\n”);
document.write(ob2.getClass()+”\n”);
最近,朋友要给他的客户与客户交流,涉及一些很重要的信息,通过QQ,MSN感觉很不可靠,于是请我写一个加密解密工具,防止信息在中途被截取。
解密工具直接交给客户,而交流信息通过E-mail或QQ。汗,我等小鸟怎么会那种高深的东东,实在是。。。为了朋友,赴刀山,下火海,奋斗了一个晚上,终于写出来了一个。好东西不敢分享,发出来共享给大家,高手见笑了。
原文地址为:http://miaoqiyuan.cn/p/javascript-jiami
因为朋友特别说是很重要的信息,我想到了以前学C的时候有一个把每个字符的编码读取出来加13的一个算法。正巧Javascript中有一个charCodeAt,呵呵,把要加密的内容,依次对出每个字符的字符编码,然后做一些处理,嘎嘎。。。。只要不知道算法,还是很难破解出来的,呵呵。
具体算法还是大家自己看吧,说出来就没有意思了。本文的算法与给朋友的稍微有些差别,毕竟安全第一。下面是运行界面,还是使用了我喜欢的hta文件。代码全是Javascript。
测试地址:
加密:http://www.miaoqiyuan.cn/products/js-jiami.htm
解密:http://www.miaoqiyuan.cn/products/js-jiemi.htm
加密.hta代码(完全可以保存为html,执行效果一样)
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>设置加密邮件内容</title>
<script type="text/javascript">
function itArt(){
this.html="Hello";
this.css="color:#000;width:640px;text-indent:20px;padding:5px;border:solid 5px #666;margin:5px;background:#CCC;margin-left:auto;margin-right:auto";
this.length=0;
}
itArt.prototype = {
init:function(){
this.length=this.html.length;
},
play:function(){
this.init();
this.setPassword();
this.echo();
},
setHtml:function(v){
this.html=v;
},
setPassword:function(){
var tmp="";
for(var i=0;i<this .length;i++){
tmp+="$"+this.html.charCodeAt(i);
}
this.html=tmp;
tmp="";
for(var i=0;i<this.html.length;i+=3){
tmp+=" "+this.html.substr(i,3);
}
this.html=tmp;
tmp="";
for(var i=0;i<this.html.length;i++){
tmp+=" "+this.html.charCodeAt(i);
}
this.html=tmp;
},
echo:function(){
var t=document.createElement("div");
t.innerHTML=this.html;
if(window.ActiveXObject)
t.style.cssText=this.css;
else
t.setAttribute("style",this.css);
//不想用DOM删掉子元素了,反正各浏览器都支持
document.getElementById("x100").innerHTML="";
document.getElementById("x100").appendChild(t);
}
}
function setPassword(t){
if(t!=""){
var demo=new itArt();
demo.setHtml(t);
demo.play();
}else{
alert("请输入内容开始加密");
}
}
window.onload=function(){
setPassword("你好,猜猜我给你的密文是什么? 哈哈,猜不到吧");
}
</script>
</this></script></head>
<body>
<textarea style="display:block;color:#000;width:640px;height:280px;text-indent:20px;border:solid 5px #666;margin:5px;background:#FFF;margin-left:auto;margin-right:auto" ondblclick="setPassword(this.value);" title="双击开始加密">你好,猜猜我给你的密文是什么? 哈哈,猜不到吧</textarea>
<div id="x100">
</div>
</body>
解密.hta代码
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>获取加密邮件内容</title>
<script type="text/javascript">
function itArt(){
this.html="Hello";
this.css="color:#000;width:640px;text-indent:20px;padding:5px;border:solid 5px #666;margin:5px;background:#CCC;margin-left:auto;margin-right:auto";
this.length=0;
}
itArt.prototype [...]
感谢小秦帮我指出错误:
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 [...]
朋友手中有上千个域名,现在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来生成。
[...]
学习Javascript快四年了。因为最初是从实践开始学的,真正系统的学习到了06年才开始。虽然学的时间够长了,曾经经历过两次瓶颈,第一次就是JS的对象。在初级教程中,JavaScript创建对象的方法基本上都是function,而且网网一带而过。所以如果只是买一本Javascript入门书开始学习JavaScript很容易遇到瓶颈。今天我写这篇文章,算是帮帮比我还菜的菜鸟,快速掌握Javscript创建对象的方法吧。
首先来介绍一下在Javascript书籍上最常见的一中方式function方式
function 对象名() {
this.变量1=变量1的值;
this.变量2=变量2的值;
this.函数1= function() {
函数体
};
this.函数2= function() {
函数体
};
……;
}
说明:
(1)其内的变量或者函数前必需写上this关键字;
(2)对象的内容与值以等号分隔,成对出现;
(3)包含的变量或者函数之间以分号分隔。
(4)函数需要写在function(){}的大括号之内。
例子:
function miaoqiyuan() {
this.name="苗启源";
this.nickname="飞猫,mqycn";
this.homeurl=function() {
alert("http://www.miaoqiyuan.cn");
};
this.gohome=function() {
location.href="http://www.miaoqiyuan.cn";
}
}
第二种:JSON方式
var 对象名 = {
变量1: 变量1的值,
变量2: 变量2的值,
函数1: function(){
函数体
},
函数2: function(){
函数体
},
……
};
说明:
(1)大括号内直接填写变量或者函数;
(2)对象的内容与值以冒号分隔,成对出现;
(3)包含的变量或者函数之间以逗号分隔;
(4)函数需要写在function(){}的大括号之内。
例子:
var miaoqiyuan = {
name:"苗启源",
nickname:"飞猫,mqycn",
homeurl: function() {
alert("http://www.miaoqiyuan.cn");
},
gohome: function() {
location.href="http://www.miaoqiyuan.cn";
}
};
第三种:原型方式
var 对象名 = {};
对象名.prototype.变量1=变量1的值;
对象名.prototype.变量2=变量2的值;
对象名.prototype.函数1= function() {
函数体
};
对象名.prototype.函数2= function() {
函数体
};
……;
说明:
(1)初始对象体内可以不定义任何东西;
(2)在要定义的变量前加“对象名.prototype.”的格式;
(3)对象的内容与值以等号分隔,成对出现;
(4)包含的变量或者函数之间以分号分隔,也可以省去分号。
(5)函数需要写在function(){}的大括号之内。
例子:
var data = {};
data.prototype.name ="苗启源";
data.prototype.nickname ="mqycn,飞猫";
data.prototype.homeurl = function() {
alert("http://www.miaoqiyuan.cn");
};
data.prototype.gohome= function() {
location.href="http://www.miaoqiyuan.cn";
};
第四种为create方式,该方式利用了Prototype JavaScript组件库,很少见有人用。
var 对象名 = Class.create();
Object.extend(对象名.prototype, {
变量1: [...]