苗启源的部落格Javascript - http://www.miaoqiyuan.cn Fri, 30 Dec 2011 16:20:41 +0000 http://wordpress.org/?v=2.9.1 en hourly 1 巧用JS复制网页内容 http://www.miaoqiyuan.cn/p/js-fav-copy http://www.miaoqiyuan.cn/p/js-fav-copy#comments Sun, 19 Dec 2010 12:07:20 +0000 mqycn http://www.miaoqiyuan.cn/?p=717 最近公司想整理下业务,看看有什么漏掉的订单。万网,息壤的业务比较多。万网的可以导出csv,而息壤就悲剧了。好几百页,只能一条一条的复制,郁闷。受QQ云输入法的影响,将JS保存到收藏夹,点击链接执行JS,加载外部JS创建表单,通过DOM获取内容,提交到本地的数据库。剩下的就好处理了。

1、新建收藏夹项目,路径填写:

javascript:(function(){$tmp=document.createElement("script");$tmp.src='http://192.168.99.29/_app/xirang.js';document.getElementsByTagName("head")[0].appendChild($tmp);})();

2、本地架设好服务器,xirang.js内容如下:

(function(){
  $tmp=document.createElement("div");
  $tmp.innerHTML=' <form action="http://192.168.99.29/_app/xirang.asp" style="display:none" method="post" id="__tmp_form"><textarea name="txtdb"></textarea></form>';
  document.getElementsByTagName("body")[0].appendChild($tmp);}
)();
hostlist = (function(){
  _t=document.getElementsByTagName("table");
  for(i=0;i<_t.length;i++){
    if(_t[i].getAttribute("className") == "listtable"){
      return _t[i];
    }
  }
  return "";
})();
if(typeof(hostlist) == "object"){
  __tmp_frm = document.getElementById("__tmp_form");
  __tmp_frm.txtdb.value = hostlist.innerHTML;
  __tmp_frm.submit();
}else{
  if(confirm("没有找到数据,点确定返回第一页")){
    location.href = "http://www.xrnet.cn/store/member.php?module=mysite&start_item=0&search=&sort_order=expiry_date&sort_order_desc=1";
  };
};

3、现在点击收藏夹中的项目,主机列表的内容(HTML代码)就到了一个表单中,并提交到了:http://192.168.99.29/_app/xirang.asp。

4、建立一个xirang.asp,保存内容。

  set conn = server.createobject("ADODB.Connection")
  conn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("xirang.mdb")
  set rs = server.createobject("ADODB.Recordset")

  frmstr = request.servervariables("HTTP_REFERER")
  if frmstr = "" then
    rs.open "select txt from txtdb",conn,1,1
    do while not rs.eof
      response.write rs(0)
      response.flush()
      rs.movenext
    loop
  else
    tmpstr = "<table width=""100%"" border=""1"">" & request.form("txtdb") & "</table>"
    stanum = split(mid(frmstr,instr(frmstr,"start_item")+11),"&")(0)
    if isnumeric(stanum) then stanum = cLng(stanum) else stanum = 0
    nxtnum = stanum + 20

    rs.open "select * from txtdb",conn,3,2
    rs.addnew
    rs("txt") = tmpstr
    rs("pag") = stanum
    rs.update
    rs.close
    set rs = nothing
    set conn = nothing

    response.redirect "http://www.xrnet.cn/store/member.php?module=mysite&start_item=" & nxtnum & "&search=&sort_order=expiry_date&sort_order_desc=1"
  end if

5、不停的点击收藏夹的,直到最后一页。

6、直接用浏览器打开,http://192.168.99.29/_app/xirang.asp,就导出了列表的数据。 另存为网页,改后缀名为.xls,用excel打开,另存为excel格式。用access/mssql导入,有脚本处理就可以了。这些不在本文的讨论范围,不提供代码。

这种方法,可以保存任何内容。本人现在对外接单,如果有网站程序开发/重构的需求,欢迎和我联系。QQ:77068320

]]>
http://www.miaoqiyuan.cn/p/js-fav-copy/feed 0
Javascript 电话匹配脚本 http://www.miaoqiyuan.cn/p/javascript-tel-match http://www.miaoqiyuan.cn/p/javascript-tel-match#comments Wed, 20 Oct 2010 13:28:04 +0000 mqycn http://www.miaoqiyuan.cn/?p=704 最近朋友让帮忙写个电话匹配脚本。能支持的电话有手机号,电话号码。手机号、电话区号前面均可带零。

<pre><script type="text/javascript">
var $ = {
'blue':'<span style=color:#090>[OK]</span>',
'red':'<span style=color:#FAA>Bad.</span>'
}
var ttt = Array(
'+86.053912345678',
'015854999261',
'15854999261',
'158549992161',
'+86.5391234567'
);
for(i=0;i<ttt.length;i++){
  document.writeln(ttt[i] + "\t: " + $[(ttt[i].match(/^(\+86\.0?\d{10,11}|(015|013|15|13)\d{9})$/ig)?"blue":"red")]);
}
</script>
]]>
http://www.miaoqiyuan.cn/p/javascript-tel-match/feed 0
新写的一个ajax类,用于新项目cms客户端 http://www.miaoqiyuan.cn/p/ajax-function http://www.miaoqiyuan.cn/p/ajax-function#comments Mon, 04 Jan 2010 03:42:42 +0000 mqycn http://www.miaoqiyuan.cn/?p=462 这个函数我觉得还是比较实用的,用于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框剪,集合了所有的功能,哈哈哈。

]]>
http://www.miaoqiyuan.cn/p/ajax-function/feed 0
可以方便的给DOM对象添加方法,可支持所有浏览器 http://www.miaoqiyuan.cn/p/set-object http://www.miaoqiyuan.cn/p/set-object#comments Fri, 13 Nov 2009 01:30:32 +0000 mqycn http://www.miaoqiyuan.cn/?p=422
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");
]]>
http://www.miaoqiyuan.cn/p/set-object/feed 2
用Javascript实现邮件加密,写了一个类 http://www.miaoqiyuan.cn/p/javascript-jiami http://www.miaoqiyuan.cn/p/javascript-jiami#comments Fri, 02 Jan 2009 14:18:38 +0000 mqycn http://miaoqiyuan.cn/?p=267        最近,朋友要给他的客户与客户交流,涉及一些很重要的信息,通过QQ,MSN感觉很不可靠,于是请我写一个加密解密工具,防止信息在中途被截取。

      解密工具直接交给客户,而交流信息通过E-mail或QQ。汗,我等小鸟怎么会那种高深的东东,实在是。。。为了朋友,赴刀山,下火海,奋斗了一个晚上,终于写出来了一个。好东西不敢分享,发出来共享给大家,高手见笑了。

    原文地址为:http://miaoqiyuan.cn/p/javascript-jiami

    因为朋友特别说是很重要的信息,我想到了以前学C的时候有一个把每个字符的编码读取出来加13的一个算法。正巧Javascript中有一个charCodeAt,呵呵,把要加密的内容,依次对出每个字符的字符编码,然后做一些处理,嘎嘎。。。。只要不知道算法,还是很难破解出来的,呵呵。

    具体算法还是大家自己看吧,说出来就没有意思了。本文的算法与给朋友的稍微有些差别,毕竟安全第一。下面是运行界面,还是使用了我喜欢的hta文件。代码全是Javascript。

js-jiami

js-jiemi

测试地址:
加密: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 = {
	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=this.html.split(" "),tmps="";
		for(i=0;i<tmp .length;i++){
			tmps+=String.fromCharCode(tmp[i]);
		}
		this.html=tmps.replace(" ","");
		tmps="";
		tmp=this.html.split("$");
		for(i=0;i<tmp.length;i++){
			if(tmp[i]!=""&&tmp[i]!=0){
				tmps+=String.fromCharCode(tmp[i].replace(" ",""));
			}
		}
		this.html=tmps;
	},
	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);
	}
}
 
demo=new itArt();
demo.setHtml();
function getPassword(t){
	if(t!=""){
	var demo=new itArt();
	demo.setHtml(t);
	demo.play();
	}else{
		alert("请输入内容开始解密");
	}
}
window.onload=function(){
	getPassword("32 36 50 48 32 51 50 48 32 36 50 50 32 57 48 57 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 50 57 32 52 54 56 32 36 50 53 32 49 48 53 32 36 51 50 32 52 55 51 32 36 50 48 32 51 50 48 32 36 51 48 32 51 52 48 32 36 50 51 32 52 57 52 32 36 50 53 32 57 57 49 32 36 50 54 32 49 53 57 32 36 50 48 32 49 54 48 32 36 50 48 32 48 52 48 32 36 54 53 32 51 49 49 32 36 51 50 32 36 50 49 32 55 48 52 32 36 50 49 32 55 48 52 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 49 57 32 57 56 49 32 36 50 49 32 48 52 48 32 36 50 49 32 53 52 51");
}
</script>
</tmp></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="getPassword(this.value);" title="双击开始解密">32 36 50 48 32 51 50 48 32 36 50 50 32 57 48 57 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 50 57 32 52 54 56 32 36 50 53 32 49 48 53 32 36 51 50 32 52 55 51 32 36 50 48 32 51 50 48 32 36 51 48 32 51 52 48 32 36 50 51 32 52 57 52 32 36 50 53 32 57 57 49 32 36 50 54 32 49 53 57 32 36 50 48 32 49 54 48 32 36 50 48 32 48 52 48 32 36 54 53 32 51 49 49 32 36 51 50 32 36 50 49 32 55 48 52 32 36 50 49 32 55 48 52 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 49 57 32 57 56 49 32 36 50 49 32 48 52 48 32 36 50 49 32 53 52 51</textarea>
<div id="x100">
</div>
</body>
]]>
http://www.miaoqiyuan.cn/p/javascript-jiami/feed 1
FlyCat(CatSeven) 美女图片程序开发动态 http://www.miaoqiyuan.cn/p/flycat-meinv-cms-catseven http://www.miaoqiyuan.cn/p/flycat-meinv-cms-catseven#comments Tue, 23 Dec 2008 18:41:31 +0000 mqycn http://miaoqiyuan.cn/?p=234 因为周日加班,所以程序的发布计划被完全打乱,本人决定在细节上做一下修改,于元旦发布。

FlyCat(CatSeven) 美女图片程序框架完成,预计下周一即可发布。

登陆图片使用了UGUG.CN上的404错误页的背景图。

后台顶部导航条参考了139邮箱的导航。
后台仅有一个页面,所有功能都由Ajax请求,并输出结果。

]]>
http://www.miaoqiyuan.cn/p/flycat-meinv-cms-catseven/feed 0
怎样创建Javascript对象? http://www.miaoqiyuan.cn/p/zenyang-chuangjian-javascript-duixiang http://www.miaoqiyuan.cn/p/zenyang-chuangjian-javascript-duixiang#comments Wed, 17 Dec 2008 12:31:20 +0000 mqycn http://miaoqiyuan.cn/?p=213 感谢小秦帮我指出错误:
  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 = Class.create();
Object.extend(miaoqiyuan.prototype,{
	name:"苗启源",
	nickname:"飞猫,mqycn",
	homeurl: function() {
		alert("http://www.miaoqiyuan.cn");
	},
	gohome: function() {
		location.href="http://www.miaoqiyuan.cn";
	}
});
var m=new miaoqiyuan;
m.homeurl();

]]>
http://www.miaoqiyuan.cn/p/zenyang-chuangjian-javascript-duixiang/feed 2
域名统计筛选程序,生成Excel文件(.xls)或HTML网页文件(.html) http://www.miaoqiyuan.cn/p/yuming-tj-to-excel-html-xls http://www.miaoqiyuan.cn/p/yuming-tj-to-excel-html-xls#comments Tue, 09 Dec 2008 15:03:14 +0000 mqycn http://miaoqiyuan.cn/?p=205 朋友手中有上千个域名,现在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控制的网页。演示页面:http://www.miaoqiyuan.cn/products/js-array-ymtj.html

<html><head><title>生成结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
var rs=new Array();
rs[1]=Array('sjtian','cn',6,'字母');
rs[2]=Array('zhaozhetao','cn',10,'字母');
rs[3]=Array('qiangjiaoshu','cn',12,'字母');
rs[4]=Array('bszange','cn',7,'字母');
rs[5]=Array('6688fafa','cn',8,'杂交');
rs[6]=Array('xswjm','cn',5,'字母');
rs[7]=Array('fpjtw','cn',5,'字母');
rs[8]=Array('jssj','js.cn',4,'字母');
rs[9]=Array('chengzhun','com',9,'字母');
rs[10]=Array('yfxqqiu','cn',7,'字母');
</script>
<script type="text/javascript">
var __res,__lx,__ws,__hz,__j,__isrun,__rscount=0;
var __mqy=function(){
	//判断是否在进程中,如果在进程中则退成,否则将进程设为活动
	if(__isrun==1)
		return eval(__sorry("还在运算中,你想累死你的爱机?"));
	else
		__isrun=1;
	//和朋友开个玩笑
	var __mm=confirm("吴哥哥,你确定请我吃MM吗?");
	if(__mm==false)
		return eval(__sorry("好,你不请我吃,那我不工作了"));
	if(typeof(__res)!="object")
		__res=document.getElementById("__res");
 
	//改变字体颜色,背景,提示现在程序正在执行中。
	__res.style.background="#FF0";
	__res.style.color="#F00";
	__res.innerHTML="<p>谢谢吴哥哥请我吃MM,正在生成中,请稍后。。。</p><p>因为数据过多,程序可能执行有点慢,请耐心等候</p>";
 
	//一秒之后执行程序,这样做是因为有时候DOM修改还没有生效,如果数据过多,进入假死状态,用户以为真死机了
	//给程序一秒中的反应时间
	setTimeout("__run()",1000);
}
 
//主要查询程序就是它啦
var __run=function(){
	//获取各个Select的值
	__ws=document.getElementById("_ws").value;
	__hz=document.getElementById("_hz").value;
	__lx=document.getElementById("_lx").value;
	__j="";
	for(i=1;i<rs .length;i++){
		//设置输出HTML
		var _isok="<li>"+rs[i][0]+"."+rs[i][1]+"";
		//只有不符合一下条件的才是符合我们要筛选的结果
		//虽然只有一个if,大家可以仔细看看,包含了十几种情况
		if(__ws!="all"&&__ws!=rs[i][2]||__hz!="all"&&__hz!=rs[i][1]||__lx!="all"&&__lx!=rs[i][3])
			_isok="";
		else
			//如果符合条件,符合条件的结果数加一
			__rscount++;
		//将判读结果附加到__j
		__j+=_isok;
	}
	if(__j=="")
		//如果__j没有改变,说明没有符合的条件记录
		__res.innerHTML="<p>没有找到任何记录</p>";
	else
		//输出符合条件的记录数及筛选结果
		__res.innerHTML="<p class=c>共找到"+__rscount+"条记录。</p>"+__j;
	__res.style.background="#0F0";
	__res.style.color="#000";
	//修改运行状态为未运行
	__isrun=0;
	//修改符合条件记录数为0,供下次查询使用
	__rscount=0;
}
var __sorry=function(t){
	alert(t);
}
</rs></script>
<style type="text/css">
div{width:800px;background:#CCC;border:solid 2px #666;margin-top:10px;padding:10px;}
div p.c{color:#F00;background:#FF0;border:solid #333 2px;padding:5px;}
</style>
</head>
<body>
<div>
按长度筛选:
<select id="_ws">
	<option value="all">不区分长度</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
</select>
按类型筛选:
<select id="_lx">
	<option value="all">不区分类型</option>
	<option value="字母">字母(abc.com)</option>
	<option value="数字">数字(123.com)</option>
	<option value="杂交">杂交(f8.com)</option>
</select>
按后缀筛选:
<select id="_hz">
	<option value="all">不区分后缀</option>
	<option value="org">org</option>
	<option value="com">com</option>
	<option value="net">net</option>
	<option value="cn">cn</option>
</select>
<input type="button" onclick="__mqy();" value="立即筛选" />
</div>
<div id="__res">
	吴哥哥,你在上边选择你的条件
</div>
</body>
</html>

网页写好了,接下来要做的就是让vbscript脚本读取当前目录中所有的txt文件,来生成html
代码如下(附件包中的js.vbs):

'域名统计程序,生成html结果
'通过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")
 
'判断是否有生成的结果ok.html,如果有,则删除
if fso.fileexists(mappath("ok.html")) then fso.getfile(mappath("ok.html")).delete
 
'创建一个ok.html
set fto=fso.createtextfile(mappath("ok.html"),2)
wscript.echo "吴哥哥,请稍等,我正在为您工作中。。。" 
scrt="<html><head><title>运行结果</title><meta http-equiv='Content-Type' content='t"
scrt=scrt+"ext/html; charset=gb2312' /><script type='text/javascript'>"
fto.writeline scrt
fto.writeline "var rs=new Array();"
 
'寻找当前目录中的所有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)
				if wss="" then wss=ws
				for each wsi in split(wss,"|")
					if cint(wsi)=ws then
						wsu=cint(ws)
						exit for
					end if
				next
				if wsu<>ws then
					wss=wss&"|"&ws
				end if
 
				'获取域名后缀
				hz=replace(rs,ym&".","")
				if hzs="" then hzs=hz
				for each hzi in split(hzs,"|")
					if hzi=hz then
						hzu=hz
						exit for
					end if
				next
				if hzu<>hz then
					hzs=hzs&"|"&hz
				end if
 
				'分析域名类型,如果ym为数字则为数字
				if isnumeric(ym) then
					lx="数字"
				'否则,如果出现数字则为杂交
				elseif iszajiao(ym)=1 then
					lx="杂交"
				'其他类型就剩下字母了
				else
					lx="字母"
				end if
				fto.writeline "rs["&rsi&"]=Array('"&ym&"','"&hz&"',"&ws&",'"&lx&"');"
			end if
		loop
	end if
next
scrt="</script><script type='text/javascript'>var __res,__lx,__ws,__hz,__j,__isrun,"
scrt=scrt+"__rscount=0;var __mqy=function(){if(__isrun==1)return eval(__sorry('还在"
scrt=scrt+"运算中,你想累死你的爱机?'));else __isrun=1;var __mm=confirm('吴哥哥,你"
scrt=scrt+"确定请我吃MM吗?');if(__mm==false)return eval(__sorry('好,你不请我吃,那"
scrt=scrt+"我不工作了'));if(typeof(__res)!='object')__res=document.getElementById('__"
scrt=scrt+"res');__res.style.background='#FF0';__res.style.color='#F00';__res.innerHTM"
scrt=scrt+"L='<p>谢谢吴哥哥请我吃MM,正在生成中,请稍后。。。</p><p>因为数据过多,程序"
scrt=scrt+"可能执行有点慢,请耐心等候</p>';setTimeout('__run()',1000);};var __run=funct"
scrt=scrt+"ion(){__ws=document.getElementById('_ws').value;__hz=document.getElementById"
scrt=scrt+"('_hz').value;__lx=document.getElementById('_lx').value;__j='';for(i=1;i<rs ."
scrt=scrt+"length;i++){var _isok='<li>'+rs[i][0]+'.'+rs[i][1]+'';if(__ws!='all'&&__"
scrt=scrt+"ws!=rs[i][2]||__hz!='all'&&__hz!=rs[i][1]||__lx!='all'&&__lx!=rs[i][3])_isok=''"
scrt=scrt+";else __rscount++;__j+=_isok;}if(__j=='')__res.innerHTML='<p>没有找到任何记录< "
scrt=scrt+"/p>';else __res.innerHTML='</p><p class=c>共找到'+__rscount+'条记录。</p>'+__j;__res"
scrt=scrt+".style.background='#0F0';__res.style.color='#000';__isrun=0;__rscount=0;};var __so"
scrt=scrt+"rry=function(t){alert(t);}</rs></script><style type='text/css'>div{width:800px;backgroun"
scrt=scrt+"d:#CCC;border:solid 2px #666;margin-top:10px;padding:10px;}div p.c{color:#F00;backg"
scrt=scrt+"round:#FF0;border:solid #333 2px;padding:5px;}</style></head><body><div>按长度筛选:"
scrt=scrt+"<select id='_ws'><option value='all'>不区分长度</option>"
fto.writeline scrt
scrt=""
for each wsi in split(wss,"|")
	fto.writeline "<option value='"&wsi&"'>"&wsi&"</option>"
next
scrt="</select> 按类型筛选<select id='_lx'><option value='all'> 不区分类型</option><option valu"
scrt=scrt+"e='字母'>字母(abc.com)</option><option value='数字'>数字(123.com)</option><option "
scrt=scrt+"value='杂交'>杂交(f8.com)</option></select> 按后缀筛选<select id='_hz'><option value"
scrt=scrt+"='all'>不区分后缀</option>"
fto.writeline scrt
scrt=""
for each hzi in split(hzs,"|")
	fto.writeline "<option value='"&hzi&"'>"&hzi&"</option>"
next
scrt="</select><input type='button' onclick='__mqy();' value='立即筛选' /></div><div id='__res'>"
scrt=scrt+"吴哥哥,你在上边选择你的条</div></body></html>"
fto.writeline scrt
fto.close
set fto=nothing
msgbox "吴哥哥,我帮你完成工作了,怎么谢我呢?请我吃MM吧"

忙了大半个晚上终于搞定了。哈哈,启源果然是天才(YY一下)。

本程序可以智能的读取程序所在目录中的所有txt文件,数据格式为每行一个域名。

现在cn域名续费涨价了,如果你手上也有很多域名,不妨用本程序来筛选一下,我已经打包成rar文件,供大家下载。
下载地址:http://www.miaoqiyuan.cn/products/yuming-tj-to-excel-html-xls.rar

转帖请注明出处:域名统计筛选程序,生成Excel文件(.xls)或HTML网页文件(.html)(http://www.miaoqiyuan.cn/p/yuming-tj-to-excel-html-xls)

]]>
http://www.miaoqiyuan.cn/p/yuming-tj-to-excel-html-xls/feed 2
公司网站使用Mapbar提供的API整合了地图功能 http://www.miaoqiyuan.cn/p/mapbar-api http://www.miaoqiyuan.cn/p/mapbar-api#comments Mon, 01 Dec 2008 16:23:59 +0000 mqycn http://miaoqiyuan.cn/?p=196 演示地址: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>
]]>
http://www.miaoqiyuan.cn/p/mapbar-api/feed 0
用VBScript和Javascript编写列出所有驱动器所有目录所有文件的资源管理器 http://www.miaoqiyuan.cn/p/drives-files-subfiles-asp-vbscript-javascript http://www.miaoqiyuan.cn/p/drives-files-subfiles-asp-vbscript-javascript#comments Mon, 01 Dec 2008 02:56:58 +0000 mqycn http://miaoqiyuan.cn/?p=193

<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=" selected" else x=""
			j=1
			pathlist=pathlist&"<option value="""&xx&""" title="""&xx&""""&x&">"&xx&"</option>"
		next
	end if
	pathlist=pathlist&"</select>"
	getPath=pathlist
End Function
 
Sub Loading
	FileMan("D:")
	DriversMan()
End Sub
 
function openFile(v)
	window.open v
end function
 
set fso=CreateObject("Scripting.FileSystemObject")
</script>
<script type="text/javascript">
function gettextarea(){
	ores=document.getElementById("res");
}
function getV(_id,ji){
	var sel=document.getElementsByTagName("select")[ji];
	sel.uid=_id;
	sel.onchange=function(){
		for(i=0;i<sel .options.length;i++){
			if(sel.options[i].selected!=""){
				document.getElementById(sel.uid).value=sel.options[i].value;
			}
		}
	}
}
function _ch(id){
	getV(id,1);
}
function _chf(id){
	getV(id,2);
}
function FileMan(Path){
	var oFm=document.getElementById("fileman");
	oFm.innerHTML=getPath("width:90%;\"  size=\"13",Path);
}
function DriversMan(){
	var oDm=document.getElementById("driversman");
	oDm.innerHTML=getPath("width:9%;\"  size=\"26","");
}
</script>
</sel></script></meta></head>
<body style="background:#D4D0C8;text-align:center" onload="Loading">
<div style="width:100%;height:100%">
	<div><span id="driversman"></span><span id="fileman"></span></div>
	<div>
		<input value="请点击选择目录" onclick="javascript:_ch(this.id);" id="__rst" readonly/>
		<input value="请点击选择目录"  onclick="javascript:_ch(this.id);" id="__res"  readonly/>
		<input value="请点击选择文件" onclick="javascript:_chf(this.id);" id="__rstf" readonly/>
		<input value="请点击选择文件"  onclick="javascript:_chf(this.id);" id="__resf"  readonly/>
		<input value="请点击选择目录" onclick="javascript:_ch(this.id);" id="__rst1" readonly/>
		<input value="请点击选择目录"  onclick="javascript:_ch(this.id);" id="__res1"  readonly/>
		<input value="请点击选择文件" onclick="javascript:_chf(this.id);" id="__rstf1" readonly/>
		<input value="请点击选择文件"  onclick="javascript:_chf(this.id);" id="__resf1"  readonly/>
		<input value="请点击选择目录" onclick="javascript:_ch(this.id);" id="__rst2" readonly/>
		<input value="请点击选择目录"  onclick="javascript:_ch(this.id);" id="__res2"  readonly/>
		<input value="请点击选择文件" onclick="javascript:_chf(this.id);" id="__rstf2" readonly/>
		<input value="请点击选择文件"  onclick="javascript:_chf(this.id);" id="__resf2"  readonly/>
	</div>
</div>
</body>
</html>

双击盘符目录打开该目录,双击文件可打开文件,点击下面的文本框,可以获取目录与文件名
程序比较简单,就不加注释了

]]>
http://www.miaoqiyuan.cn/p/drives-files-subfiles-asp-vbscript-javascript/feed 0