2008年12月7日星期日

JS 里用正则表达式替换字符串

方法如下:


//参数中的 g 表示全部匹配,i表示忽略大小写
//str='toaction=t23rue';
//str='toaction=t23rue';
str='toactioN=True';
str=str.replace(/toaction=[\w]+/gi,'toaction=false');
alert(str);


举一个使用的下面一个例子:


function addQueryString()
{
// thickbox query string
var tbString = $_('compStart').alt;

if($_('toaction').checked) tbString = tbString.replace(/toaction=[\w]+/gi,'toaction=true');
else tbString = tbString.replace(/toaction=[\w]+/gi,'toaction=false');

if($_('towinner').checked) tbString = tbString.replace(/towinner=[\w]+/gi,'towinner=true');
else tbString = tbString.replace(/towinner=[\w]+/gi,'towinner=false');

$_('compStart').alt=tbString;
}

Javascript 获取链接(url)参数的方法

摘要: 有时我们需要在客户端获取链接参数,一个常见的方法是将链接当做字符串,按照链接的格式分解,然后获取对应的参数值。本文给出的就是这个流程的具体实现方法。

当然,我们也可以用正则直接匹配,文章中也给出了一个正则的例子。

用正则匹配的方式:
Javascript:
<script language="JavaScript">
<!--
function getQueryStringRegExp(name)
{
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test('http://localhost/test.html?aa=bb&test=cc+dd&ee=ff')) {
return unescape(RegExp.$2.replace(/\+/g, " "));
}
return '';
};
//http://localhost/test.html?aa=bb&test=cc+dd&ee=ff
alert(getQueryStringRegExp('test'));
//-->
</script>


分解链接的方式:
Javascript:
<script type="text/javascript">
<!--
// 说明:Javascript 获取链接(url)参数的方法
// 整理:http://www.CodeBit.cn

function getQueryString(name)
{
// 如果链接没有参数,或者链接中不存在我们要获取的参数,直接返回空
if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1)
{
return '';
}

// 获取链接中参数部分
var queryString = location.href.substring(location.href.indexOf("?")+1);

// 分离参数对 ?key=value&key2=value2
var parameters = queryString.split("&");

var pos, paraName, paraValue;
for(var i=0; i<parameters.length; i++)
{
// 获取等号位置
pos = parameters[i].indexOf('=');
if(pos == -1) { continue; }

// 获取name 和 value
paraName = parameters[i].substring(0, pos);
paraValue = parameters[i].substring(pos + 1);

// 如果查询的name等于当前name,就返回当前值,同时,将链接中的+号还原成空格
if(paraName == name)
{
return unescape(paraValue.replace(/\+/g, " "));
}
}
return '';
};

//http://localhost/test.html?aa=bb&test=cc+dd&ee=ff
alert(getQueryString('test'));
//-->
</script>

jquery 对 checkbox 实现全选效果 (checkbox控制 | button控制)

以下有两种方法:
1. 使用 checkbox 进行控制 全选checkbox
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Jquery click all </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<input type="checkbox" id="checkbox1" name="checkbox1" onClick="clickall(this);" >
<input type="checkbox" id="checkname1" name="checkname[]" value="1"/>1
<input type="checkbox" id="checkname2" name="checkname[]" value="2"/>2


<script type="text/javascript" language="javascript">
function clickall(cb){
if(cb.checked) {
$('input[@name="checkname[]"]').attr('checked',true);
} else {
$('input[@name="checkname[]"]').attr('checked',false);
}
}
</script>
</body>
</html>


2. 使用 Button 进行控制 全选checkbox
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Jquery click all </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
$("#checkall").click(function() {
$("input[@name='checkname[]']").each(function() {
$(this).attr("checked", true);
});
});
$("#delcheckall").click(function() {
$("input[@name='checkname[]']").each(function() {
$(this).attr("checked", false);
});
});
});
</script>
<input type='checkbox' id='id1' name='checkname[]' value='1' />value1
<input type='checkbox' id='id2' name='checkname[]' value='2' />value2
<input type='checkbox' id='id3' name='checkname[]' value='3' />value3
<input type="button" id="checkall" name="checkall" value="全选" />
<input type="button" id="delcheckall" name="delcheckall" value="取消全选" />
</body>
</html>

在js中声明变量时,什么时候需要var,什么时候不需要?

在js中声明变量时,什么时候需要var,什么时候不需要???

关键问题:
在function内部,用var是局部变量,不用var是全局变量。
这个问题不搞清楚,就不是风格的好坏了,可能会导致功能错误。
在function外,用不用都是全局变量。

理解“JS变量定义”的概念

首先,那种不用var就直接赋值的做法,javascript认为你第一次赋值的同时也就是做了定义。如果你是初学者,我建议不妨将这种做法看作一种不规范用法,你就当它根本不存在,问题就简单了。

var aString;
是纯粹的变量定义(但只能在函数内部用)

var aString = "100";
是变量定义,并同时赋值。在函数外部必须这么用,如果在函数内部,就等效于:
var aString;
aString = "100";

赋值可以无数次,定义只能一次!就好比一个人的性格可以不断改变,但出生只能有一次!

2008年12月4日星期四

apache rewrite Rule 详解

作为RewriteRule指令的第三个参数, Flags是一个包含以逗号分隔的下列标记的列表:

'redirect|R [=code]' (强制重定向 redirect)
以 http://thishost[:thisport]/(使新的URL成为一个URI) 为前缀的Substitution可以强制性执行一个外部重定向。
如果code没有指定,则产生一个HTTP响应代码302(临时性移动)。
如果需要使用在300-400范围内的其他响应代码,只需在此指定这个数值即可.
另外,还可以使用下列符号名称之一: temp (默认的), permanent, seeother. 用它可以把规范化的URL反馈给客户端.
如, 重写``/~''为 ``/u/'',或对/u/user加上斜杠,等等。

注意: 在使用这个标记时,必须确保该替换字段是一个有效的URL! 否则,它会指向一个无效的位置! 并且要记住,此标记本身只是对URL加上 http://thishost[:thisport]/的前缀,重写操作仍然会继续。通常,你会希望停止重写操作而立即重定向,则还需要使用'L'标记.

'forbidden|F' (强制URL为被禁止的 forbidden)
强制当前URL为被禁止的,即,立即反馈一个HTTP响应代码403(被禁止的)。
使用这个标记,可以链接若干RewriteConds以有条件地阻塞某些URL。

'gone|G' (强制URL为已废弃的 gone)
强制当前URL为已废弃的,即,立即反馈一个HTTP响应代码410(已废弃的)。
使用这个标记,可以标明页面已经被废弃而不存在了.

'proxy|P' (强制为代理 proxy)
此标记使替换成分被内部地强制为代理请求,并立即(即, 重写规则处理立即中断)把处理移交给代理模块。
你必须确保此替换串是一个有效的(比如常见的以 http://hostname开头的)能够为Apache代理模块所处理的URI。
使用这个标记,可以把某些远程成分映射到本地服务器名称空间,从而增强了ProxyPass指令的功能。
注意: 要使用这个功能,代理模块必须编译在Apache服务器中。如果你不能确定,可以检查``httpd -l''的输出中是否有mod_proxy.c。 如果有,则mod_rewrite可以使用这个功能;如果没有,则必须启用mod_proxy并重新编译``httpd''程序。

'last|L' (最后一个规则 last)
立即停止重写操作,并不再应用其他重写规则。
它对应于Perl中的last命令或C语言中的break命令。这个标记可以阻止当前已被重写的URL为其后继的规则所重写。
举例,使用它可以重写根路径的URL('/')为实际存在的URL, 比如, '/e/www/'.

'next|N' (重新执行 next round)
重新执行重写操作(从第一个规则重新开始). 这时再次进行处理的URL已经不是原始的URL了,而是经最后一个重写规则处理的URL。
它对应于Perl中的next命令或C语言中的continue命令。
此标记可以重新开始重写操作,即, 立即回到循环的头部。
但是要小心,不要制造死循环!

'chain|C' (与下一个规则相链接 chained)
此标记使当前规则与下一个(其本身又可以与其后继规则相链接的, 并可以如此反复的)规则相链接。
它产生这样一个效果: 如果一个规则被匹配,通常会继续处理其后继规则, 即,这个标记不起作用;如果规则不能被匹配,则其后继的链接的规则会被忽略。
比如,在执行一个外部重定向时, 对一个目录级规则集,你可能需要删除``.www'' (此处不应该出现``.www''的)。

'type|T=MIME-type' (强制MIME类型 type)
强制目标文件的MIME类型为MIME-type。
比如,它可以用于模拟mod_alias中的ScriptAlias指令, 以内部地强制被映射目录中的所有文件的MIME类型为``application/x-httpd-cgi''.

'nosubreq|NS' (仅用于不对内部子请求进行处理 no internal sub-request)
在当前请求是一个内部子请求时,此标记强制重写引擎跳过该重写规则。
比如,在mod_include试图搜索可能的目录默认文件(index.xxx)时, Apache会内部地产生子请求。
对子请求,它不一定有用的,而且如果整个规则集都起作用,它甚至可能会引发错误。
所以,可以用这个标记来排除某些规则。

根据你的需要遵循以下原则: 如果你使用了有CGI脚本的URL前缀,以强制它们由CGI脚本处理, 而对子请求处理的出错率(或者开销)很高,在这种情况下,可以使用这个标记。

'nocase|NC' (忽略大小写 no case)
它使Pattern忽略大小写,即, 在Pattern与当前URL匹配时,'A-Z' 和'a-z'没有区别。

'qsappend|QSA' (追加请求串 query string append)
此标记强制重写引擎在已有的替换串中追加一个请求串,而不是简单的替换。
如果需要通过重写规则在请求串中增加信息,就可以使用这个标记。

'noescape|NE' (在输出中不对URI作转义 no URI escaping)
此标记阻止mod_rewrite对重写结果应用常规的URI转义规则。
一般情况下,特殊字符(如'%', '$', ';'等)会被转义为等值的十六进制编码。
此标记可以阻止这样的转义,以允许百分号等符号出现在输出中,
如:
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]

可以使'/foo/zed'转向到一个安全的请求'/bar?arg=P1=zed'.

'passthrough|PT' (移交给下一个处理器 pass through)
此标记强制重写引擎将内部结构request_rec中的uri字段设置为 filename字段的值,它只是一个小修改,使之能对来自其他URI到文件名翻译器的 Alias,ScriptAlias, Redirect 等指令的输出进行后续处理。
举一个能说明其含义的例子: 如果要通过mod_rewrite的重写引擎重写/abc为/def,然后通过mod_alias使/def转变为/ghi,可以这样:
RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi

如果省略了PT标记,虽然mod_rewrite运作正常, 即, 作为一个使用API的URI到文件名翻译器, 它可以重写uri=/abc/...为filename=/def/..., 但是,后续的mod_alias在试图作URI到文件名的翻译时,则会失效。
注意: 如果需要混合使用不同的包含URI到文件名翻译器的模块时, 就必须使用这个标记。。 混合使用mod_alias和mod_rewrite就是个典型的例子。

For Apache hackers
如果当前Apache API除了URI到文件名hook之外,还有一个文件名到文件名的hook, 就不需要这个标记了! 但是,如果没有这样一个hook,则此标记是唯一的解决方案。
Apache Group讨论过这个问题,并在Apache 2.0 版本中会增加这样一个hook。

'skip|S=num' (跳过后继的规则 skip)
此标记强制重写引擎跳过当前匹配规则后继的num个规则。
它可以实现一个伪if-then-else的构造: 最后一个规则是then从句,而被跳过的skip=N个规则是else从句. (它和'chain|C'标记是不同的!)

'env|E=VAR:VAL' (设置环境变量 environment variable)
此标记使环境变量VAR的值为VAL, VAL可以包含可扩展的反向引用的正则表达式$N和%N。
此标记可以多次使用以设置多个变量。
这些变量可以在其后许多情况下被间接引用,但通常是在XSSI (via ) or CGI (如 $ENV{'VAR'})中, 也可以在后继的RewriteCond指令的pattern中通过%{ENV:VAR}作引用。
使用它可以从URL中剥离并记住一些信息。

'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (设置cookie)
它在客户端浏览器上设置一个cookie。
cookie的名称是NAME,其值是VAL。
domain字段是该cookie的域,比如'.apache.org', 可选的lifetime是cookie生命期的分钟数, 可选的path是cookie的路径。
注意
绝不要忘记,在服务器级配置文件中,Pattern是作用于整个URL的。 但是在目录级配置文件中, (一般总是和特定目录名称相同的)目录前缀会在pattern匹配时被自动删除,而又在替换完毕后自动被加上。此特性对很多种重写是必须的,因为,如果没有这个剥离前缀的动作,就必须与其父目录去匹配,而这并不总是可行的。
但是有一个例外: 如果替换串以``http://''开头, 则不会附加目录前缀, 而是强制产生一个外部重定向,或者(如果使用了P标记)是一个代理操作!

注意
为了对目录级配置启用重写引擎,你必须在这些文件中设置``RewriteEngine On'', 并且打开``Options FollowSymLinks'。
如果管理员对用户目录禁用了FollowSymLinks, 则无法使用重写引擎。这个限制是为了安全而设置的。

以下是所有可能的替换组合及其含义:

在服务器级配置中(httpd.conf),对这样一个请求 ``GET /somepath/pathinfo'':


Given Rule Resulting Substitution
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 not supported, because invalid!
^/somepath(.*) otherpath$1 [R] not supported, because invalid!
^/somepath(.*) otherpath$1 [P] not supported, because invalid!
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpathvia external redirection
^/somepath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpathvia external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfovia external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfovia external redirection (the [R] flag is redundant)

^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfovia internal proxy

在/somepath的目录级配置中
(即, 目录/physical/path/to/somepath的.htaccess文件中包含 RewriteBase /somepath)
对这样一个请求``GET /somepath/localpath/pathinfo'':

Given Rule Resulting Substitution
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfovia external redirection
^localpath(.*) otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfovia external redirection
^localpath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfovia external redirection
^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfovia external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfovia external redirection(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfovia internal proxy


举例:

要重写这种形式的URL:
/ Language /~ Realname /.../ File

/u/ Username /.../ File . Language

可以把这样的对应关系保存在/path/to/file/map.txt映射文件中, 此后,只要在Apache服务器配置文件中增加下列行,即可:

RewriteLog /path/to/file/rewrite.log
RewriteMap real-to-user txt:/path/to/file/map.txt
RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1

SEO常用名词

SEO常用名词
与Source Code有关的SEO常用语:
1. Title Tag /Meta Title
<title>Smarter.com Comparison Shopping: Compare Prices, Discounts & Reviews on Millions of Products</title>
2. Meta Description
<Meta NAME="description" content="Shop and save at Smarter.com: Compare prices, coupons and rebates from thousands of online stores to get the lowest price. Before you buy, see products up-close in video reviews. Read shopping blogs, buying guides and unbiased product and website reviews to find out how other consumer's rate their purchases. There are millions of items for sale online. Comparison shop to find the right one for you at the best prices on the Internet." />
3. Meta Keyword
<meta NAME="keywords" content="comparison shopping, compare prices, product reviews, merchant reviews, compare products, shop and compare, best price, purchase and buy online, shop & save, store, shop at home, Smarter.com, site, internet, links, cost, website, consumer information, service" />
4. Other Meta Tag:
<meta content="index,follow" name="robots" />
<META NAME="ROBOTS" CONTENT="NOYDIR">
<META NAME="ROBOTS" CONTENT="NOODP">
<META name="y_key" content="5308ed89f65f99e8" />
<meta content="www.smarter.com" name="copyright" />

5. Meta Tag
Meta Title + Meta Description + Meta Keyword
6. H Tag/Header Tag
<H1>…</H1>, <H2>…</H2> etc.
7. Alt Tag
alt=” ” (适用于图片), title=””(适用于文字链接)
8. List Tag
<ul>, <ol>, <li> and <dl>, <dt>, <dd> etc.
9. Frame Tag
<frame>, <iframe>, <frameset> etc.
10. Nofollow Tag
<a href="/email.php?url=aHR0cDovL3d3dy5zbWFydGVyLmNvbS8=" rel="nofollow" >Email this Page</a>
11. <P> Tag
<p>Monday I came to you with some expiring Dell deals, and if those didn't spark your interest, maybe this HP deal will.</p>

与SEO技术相关的常用语:
SE - 搜索引擎
SERP - 搜索引擎结果页面
Search Engine Ranking/Ranking - 搜索引擎排名
Keyword Density - 关键词密度
Page Rank (简称PR值) - Google衡量网页重要性的工具,测量值范围为从1至10分别表示某网页的重要性。Google工具栏可以随时获得某网页的PR值。
Inbound Link = External Links (外部链接)- 被其他网站链接的数量
Outbound link - 一个网站链接到其他网站的数量
Internal links (内部链接)- 本网站页面之间的链接
Backward Links(反向链接)= Internal Links + External Links - 外部链接与内部链接的总和
Open Directory Project (简称ODP) - 目录索引网站,如Dmoz,Yahoo,Google
Redirection - 跳转,有301,302两种跳转方式
404/Not Found Page
Link Popularity: 链接广度
友情链接/交换链接/Reciprocal Link
One-way Link
Three-way Link
Paid Link
Hidden Link/Text/Content
SPAM = Link Spam + Content Spam - 在SEO领域里,它指的是一种有目的有计划地提高网站在搜索引擎排名的作弊技术,一旦被发现,网站将会被屏弊
Link Spam - 作弊链接/恶意链接(也有称作:link farms 链接工厂)
Keyword Stuffing - 关键词堆砌
Deceptive redirects 欺骗性重定向 - 指把用户访问的第一个页面(争夺排名页)迅速重定向至另一个内容完全不同的页面。
Shadow Domain - 这是最常见的欺骗性重定向技术,通过欺骗性重定向使用户访问另外一个网站或页面。
Doorway Page 门页- 也叫“桥页”。是为某些关键字特别制作的页面,专为搜索引擎设计,目的是提高特定关键词在搜索引擎中的排名所设计的富含目标关键词的域名,且重定向至另一域名的真实网站。搜索引擎的Spiders往往忽略对那些自动重定向到其它页的页面的检索。
Spider = Robot = Bot = Slurp – 搜索引擎爬虫
Mirror Sites/Duplicate Sites (镜象站点) - 通过复制网站的内容并分配以不同域名和服务器,以此欺骗搜索引擎对同一站点或同一页面进行多次索引。现在大多数搜索引擎都提供有能够检测镜象站点的适当的过滤系统,一旦发觉镜象站点,则原站点和镜象站点都会被从索引数据库中删除。
Duplicate Content - 複製的內容通常指的是一個頁面上的內容是從網上別的地方COPY來的,不努力工作 就想得到好排名。GOOGLE有一套很出名的過濾機制去尋找複製文本,一旦它發現兩個或更多同樣的文本它就會評估這些文檔去看哪一個是他們收錄時間最長 的,最新的網頁會被刪除或排在比較靠後的結果中。

一个强大的屏幕捕捉程序


一个强大的屏幕捕捉程序,不仅能捕捉 Windows 下的屏幕,也能捕捉 DOS 的。存盘支持的图形格式也很多。SnagIt对于系统并不会要求太高,凡Windows 98/95/NT 皆可使用,而且只要有 Windows 支持的打印机,就可以设定打印机输出,若有设定 32 位的 MAPI,还可以以电子邮件方式来输出。

sn:DBMLC-FCB3V-A33GA-JDCYY-ZB387


下载地址:http://www.chinaz.cn/soft/9620.htm