分类目录归档:站长文档

Learning Ajax 2, url, link and button

with <Ajax on Rails>
S2.3. Bringing Rails into the Picture

complex url_for example:
url_for :only_path => false, :protocol => ‘gopher:// ‘,
  :host => ‘example.com’, :controller =&gt; ‘chapter2′,
  :action => ‘myresponse’, :trailing_slash => true, :foo => ‘bar’,
  :anchor => ‘baz’
#=> ‘gopher://example.com/chapter2/myresponse?foo=bar/#baz’

ajax on rails(aor) alert:
<p><%= link_to_remote "Alert with javascript Helper", :url =>
   "/chapter2/myresponse", :success => "alert(request.responseText)" %></p>

aor insert:
<p><%= link_to_remote "Update  with javascript Helper", :url =>
  {:action => "myresponse"}, :update => "response5" %></p>
<p id="response5"></p>

Chapter 3. Introducing Prototype

3.2 Ajax Links

:method => :delete
<%= link_to "Delete", "/people/1", :method => :delete %>

==>
<a href="/people/1"
  onclick="var f = document.createElement(‘form’);
           f.style.display = ‘none’;
           this.parentNode.appendChild(f);
           f.method = ‘POST’;
           f.action = this.href;
           var m = document.createElement(‘input’);
           m.setAttribute(‘type’, ‘hidden’);
           m.setAttribute(‘name’, ‘_method’);
           m.setAttribute(‘value‘, ‘delete’);
           f.appendChild(m);
           f.submit(  );
           return false;">Delete</a>

Return false;
<a href="#"
   onclick="new Ajax.Updater(‘current_time’, ‘/chapter3/get_time’,
               {asynchronous:true, evalScripts:true});
            return false;">Check Time</a>
<div id="current_time"></div>
The link will only be followed if the expression evaluates true (or if the user has javascript turned off). That’s why the link_to_remote helper puts return false at the end of the onclick attribute.

Callbacks:
<%= link_to_remote "Check Time",
    :update   => ‘current_time’,
    :url      => { :action => ‘get_time’ },
    :before   => "$(‘indicator’).show(  )",
    :success  => "$(‘current_time’).visualEffect(‘highlight’)",
    :failure  => "alert(‘There was an error. ‘)",
    :complete => "$(‘indicator’).hide(  )" %>
<span id="indicator" style="display: none;">Loading…</span>
<div id="current_time"></div>

hide( ) and show( )
for an element to be dynamically shown via javascript, its CSS display: none property must be defined inline

this won’t work:
<style type="text/css">
  #indicator { display: none; }
</style>
<div id="indicator">Hidden DIV</div>
<script type="text/javascript">
  $("indicator").show(  ); // won’t work
</script>

But this will work:

<div id="indicator" style="display: none">Hidden DIV</div>
<script type="text/javascript">
  $("indicator").show(  ); // will work
</script>

:condition
<li><%= check_box_tag ‘checkbox’ %> Thing #1</li>
<%= link_to_remote "Delete checked items",
    :condition => "$(‘checkbox’).checked",
    :url       => { :action => ‘delete_items’ } %>

:submit
it allows you to simulate a form submission. By providing the ID of a page element, any fields contained in it will be sent along with the request.
<div id="fakeForm">
  <input type="text" name="foo" value="bar" />
</div>
<%= link_to_remote "Submit fake form",
       :submit   => "fakeForm",
       :url      => { :action => ‘repeat’ },
       :complete => "alert(request.responseText)" %>

nested forms

<form id="myForm">
  <input type="text" name="text_to_reverse" id="text_to_reverse" />
  <%= link_to_remote "Reverse field",
       :url      => { :action => ‘reverse’ },
       :submit   => "myForm",
       :complete => "$(‘text_to_reverse’).value=request.responseText" %>
  <input type="submit" />
</form>

:with
<%= link_to_remote "Link with params",
       :url      => { :action => ‘repeat’ },
       :complete => "alert(request.responseText)",
       :with     => "’foo=bar’" %>
two sets of quote marks. javascript expression

include references to javascript variables or DOM elements:
<input id="myElement" type="text" value="bar" />
<%= link_to_remote "Link with dynamic params",
       :url      => { :action => ‘repeat’ },
       :complete => "alert(request.responseText)",
       :with     => "’foo=’+escape($F(‘myElement’))" %>
escape it (so that it can safely be included in a URL query string)

link_to_function
<%= link_to_function "Toggle DIV", "$(‘indicator’).toggle(  )" %></p>
toggle( ), which hides and shows elements on the page.

button_to_function
<%= button_to_function "Greet", "alert(‘Hello world!’)" %>

combine with remote_function
<%= button_to_function "Check Time",
      remote_function(:update => "current_time",
        :url => { :action => ‘get_time’ }) %>

DIY button_to_remote
def button_to_remote(name, options = {})
  button_to_function(name, remote_function(options))
end
==>
<%= button_to_remote "Get Time Now",
      :update => "current_time",
      :url    => { :action => ‘get_time’ } %>

发表在 Ruby on Rails, 站长文档 | 留下评论

如何在linux中查找文件

本文修改自:
http://it.sohu.com/2004/06/09/32/article220453226.shtml

whereis 文件名

  寻找文件工具

  whereis 是一个小巧好用的文件寻找工具,它专门用来寻找可执行的程序、原始程序和使用手册。

如执行命令:whereis bzip2

 find [寻找的目录] [表示式]

  寻找文件工具

  find 是高级的寻找文件工具,可不像 whereis 那么“阳春白雪”。但也因为它太高级了,复杂到很多人用不熟练。我们尽量只举简单的例子。

  最简单的格式如下:

  find / -name my* -print

  这个意思是请它从最底层的主目录开始找,找出文件名是 my 开头的文件,把它显示出来。-print 选项是显示,您可把它当做固定要加上的项目。

  但它还可以用时间来找,例如:

  find /usr -atime 3 –print

  会从 /usr 目录开始往下找,找最近3天之内存取过的文件。

  find /usr -ctime 5 –print

  会从 /usr 目录开始往下找,找最近5天之内修改过的文件。

  find /doc -user jacky -name 'j*' –print

  会从 /doc 目录开始往下找,找jacky 的、文件名开头是 j的文件。

  find /doc \( -name 'ja*' -o- -name 'ma*' \) –print

  会从 /doc 目录开始往下找,找寻文件名是 ja 开头或者 ma开头的文件。

  find /doc -name '*bak' -exec rm {} \;

  会从 /doc 目录开始往下找,找到凡是文件名结尾为 bak的文件,把它删除掉。-exec 选项是执行的意思,rm 是删除命令,{ } 表示文件名,“\;”是规定的命令结尾。

locate 文件名

  寻找文件工具

  locate 也是一个寻找文件的工具,但是它不像 whereis 只能找程序文件等几种文件,也不像find那么复杂,可以算是“中庸之道”!

grep [-选项] [字串] [文件名]

  寻找某字串内容工具

  有些时候,我们存储文件时随手乱取了一个文件名,事后自己都忘了那个文件名叫什么,连开头第一个字母都想不起来。那么,如果您还记得该文件一点特殊的词语,应该可以用 grep 命令找到。

  例如,我们想在一个目录的200个文件里面,找出哪一个文件提到“排版”这个词语:

  grep 排版 *.txt

如果您想要让它凡是符合条件的只出现一次的话,加上 -l 选项就可以了

其他常用的选项还有:

  -n 同时列出该词语出现在文章的第几行。

  -c 计算一下该字串出现的次数。

  -i 比对的时候,不计较大小写的不同。

相关命令:
more [文件名]

  分页显示一个文件或任何输出结果

ls x* | more
more /etc/XF86Config

 less [文件名]

  分页显示一个文件并且可以回头

  less 的优点就是可以随时回头,最简单的用【PgUp】键就可以向上翻。

 

发表在 站长文档 | 留下评论

从Windows Xp 转到Linux (Ubuntu 6.06)上

这文章是8个多月前写的。今天(20070929)更新。

忙了四天,基本上从Windows Xp 转到了Ubuntu 6.06这个Linux操作系统上了。

为什么要转到linux?
1.比起Windows,Linux更加Free,而得到更多的自由是我孜孜不倦的人生追求。
2.工作方向向开源,协同,草根方向发展,linux比windows更能代表这个方向。
3.在Windows上进程开多了,切换程序时反应很慢。希望在linux可以解决这个问题。
4.多年的Windows使用让人感觉它很枯燥,没有新鲜感,不再能带来刺激。
5.现在的linux系统已经比较成熟,相信可以胜任工作和娱乐的要求。
6.新买了一个250G的硬盘,在新硬盘上实验新的操作系统,不用担心数据丢失,可以放手进行转换实验。

为什么选择Ubuntu?
在Rubyonrails论坛(http://www.ruby-forum.com/forum/3)上很多人说都在用Ubuntu。
Ubuntu最近好像很热, 前几天在一期<程序员>看到它已经是最多人使用的Linux操作系统。人多出了问题好打听解决办法。。。
因为听说6.06版叫Long Term Support版(LTS)版,所以虽然旧了点,还是选择了它。
虽然自己使用的是AMD Athlon64 3600+, 但据说amd64版的linux软件和硬件驱动不全,所以还是选择了i386版安装。

Ubuntu Linux操作系统官方网站:
http://www.ubuntu.com/

安装Ubuntu
http://www.ubuntu.com/products/GetUbuntu/download#lts 下载DVD镜像。 3G多,用迅雷下载,速度很快。
然后用nero将文件刻录成光盘,引导安装。人性化的对话安装方式,过程没有遇到任何问题。系统安装好了就进了gnome桌面。

自动登录
启动自动登录功能,不然每次进入桌面前要输入用户名和密码。

ADSL拨号上网
我这里连接的是小区宽带,但拨号方式和ADSL一样。用pppoeconf设置好,让系统在启动时自动拨号连接。

中文环境
Gnome我选择了英文界面,但Ubuntu可以正确识别中文字符。
字体比windows下的差多了,很不好看。我照:
http://forum.ubuntu.org.cn/viewtopic.php?t=19841
更换了字体,感觉和Windows系统没有差距了。
虽然在语言支持中选择安装了中日韩相关的语言文件,但不能调出中文输入法。
后来才知道要修改/etc/environment 文件
加入
LC_CTYPE=zh_CN.UTF-8
这时可以调出scim输入法了。同时去除了里面用不到的输入法,如二笔,日文输入等。为五笔和拼音定义了快捷键。

通过USB转换线连接的HP Laserjet 1100激光打印机
接上打印机电源后Ubuntu 6.06能自动找到打印机和它的驱动。安装后,感觉打印机的反应速度比在Windows XP慢。

USB摄像头
系统已经安装好了驱动,在Ekiga Softphone上可以看到图像,可惜这个本来就没有多少用处的摄像头在linux更是没有用武之地。。

NVIDIA Quadro NVS 280双头显卡
这个折腾得最惨烈。我安装的是一个双头的显卡,同时接两个显示器。在刚安装好ubuntu时,其中一个显示器可以显示,而另一个则是花屏的。
我先是不知道怎样安装nvidia驱动,后来才知道要把ubuntu文件源文件全使用上才有驱动安装(?)。无论怎样,最后是安装上了nvidia-glx驱动文件。
但第二个显示器还是不能正常显示。最好搞来搞去,把系统搞坏了,进不了桌面,不知道怎样入手修复,我竟然重新安装一个ubuntu。。。
后来才知道nvidia显卡可以使用TwinView技术实现双显示器功能,于是我照:
http://www.ublug.org/ubuntu/twinview/twinview-howto-breezy.html
(我打开了Option "RenderAccel" "1")
实现了第二个显示器的正常显示。
但还有问题
1.除了交换两台显示的连接线,我不选择linux登录界面出现在哪个显示器上。
2.使用vlc播放器时,无论在哪个桌面上让它全屏播放,视频画面都只会出现在主显示屏上。
3.使用mplayer播放器时,当在分辨率大的那个显示屏时让它全屏播放时,画面只使用分辨率小的那个显示屏的分辨率(这时在更改aspect ratio后可以修正这个问题)

更新ubuntu文件源
ubuntu有个自动更新安装文件的系统,叫Synaptic Package Manager,这个管理器会自动对比系统文件和/etc/apt/sources.list列表文件提供的文件版本,然后升级系统。这个源列表修改到中国区的服务器,这样更新时速度快一些。
参看:
http://wiki.ubuntu.org.cn/%E5%BF%AB%E9%80%9F%E8%AE%BE%E7%BD%AE%E6%8C%87%E5%8D%97/DapperDrake#head-ebc0c729d9417455acdd859232f278cf3127935a

更换linux内核文件
我的CPU是AMD Athlon64 3600+,为提高系统性能,将原来的linux-i386更换成linux-k7-smp内核。这时系统监视软件显示的CPU为两个了。

安装aMule
这个安装很方便,系统自带的。aMule很像eMule,更新服务器列表,下载速度也不错。
参看:http://forum.ubuntu.org.cn/viewtopic.php?t=40336&;highlight=amule
注意,文章中的sudo apt-get install amule amule-utils要换成sudo apt-get install amule amule-utils*
更新:后来经过实际使用,发现速度不如用wine模拟运行eMule的速度,所以一直使用eMule了。但有两个问题:eMule占用系统资源比较大;eMule偶尔会自动退出;但总得来说不影响使用。

安装BT下载软件
比较了多个BT下载软件,发现只有bitstormlite可以正常识别中文编码,速度也不错。
更新:发现这个软件的速度也不如用wine模拟utorrent的速度,后一直用utorrent。

安装迅雷下载软件
迅雷没有linux版本,也没有同类替代软件。所以在Linux下只能用Wine模拟机安装。我试过了迅雷5和迷你迅雷,安装后都不能启动,后经网友指点,找了一个国际版的迅雷,安装后真的可以使用!
更新:后模拟迅雷5也成功了。

使用FireFox
这回要以Firefox为最主要的浏览器了。用了几天,感觉firefox不比ie差。现在将最小字体限制到18,看网页比IE舒服多了。
linux下的firefox好像不能安装google toolbar, 为查看网站的pr值,我安装了一个seoquake插件,没想到它的功能强多了。
为了下载速度,又安装了一个DownThemAll!插件。
又自行设置了firefox和amule的关联,现在点击emule链接会将下载文件自动添加到amule下载列表去了。
Windows下Firefox可以导入IE的收藏夹,但在linux下只能导入收藏夹文件。为了导入Windows下IE的收藏夹,我先在 Windows下启动firefox,然后导入IE收藏夹,再在FireFox中将收藏夹内容导出到一个文件中,最后在linux中用FireFox导入 这个文件。。。(绕口)
让FireFox也能正常浏览BT@China, 参看:http://forum.ubuntu.org.cn/viewtopic.php?t=17327&;postdays=0&postorder=asc&start=0
更新:FF有很多插件,对日常使用和网站开发很有帮助。如ColorfullTabs, ColorZilla, FireBug, FireFTP, Link Alert, SeoQuake….

在linux下远程登录到Windows 2000服务器
本来以为这会一是一件很难的事,但经过反复搜索,得知一个叫rdesktop的软件可以完成这个工作。然后在试探性地在系统安装文件中查找,竟然意外地发现这个软件已经安装到ubuntu上了。。。

ftp工具
照系统里的安装了gFTP
更新:这个FTP不太稳定,功能也很一般。后来试用了FireFox加FireFTP插件和CrossFTP。感觉都不错。

图片工具
看图工具gThumb和图片编辑工具GIMP默认下也安装了。

看书工具
用xCHM可以打开chm文档,pdf文件原先已经可以打开。
更新:后来一直用KchmViewer看CHM文档。

安装QQ
安装了LumaQQ 2005,安装之前要安装java环境,但安装后发现不能打开QQ, 最后才发现一定要设置java解释器。。。
LumaQQ 2005可以进行QQ聊天,但好像不能视频聊天,也不能传文件。
更新:LumaQQ不能登录了,改用wine模拟QQ了。但不稳定,很少使用。

旺旺
旺旺还没有linux版本,所以只能使用网页旺旺了,虽然不能保存聊天记录,但也没有办法。
更新:用wine模拟安装了一个 旺旺。但现在淘宝网不支持FireFox支付了。所以使用VirtualBox模拟了一台虚拟机,在上面安装了一个Windows XP。基本上偶尔QQ聊天,就专门用来上淘宝网。感觉更安全。

音乐播放工具
安装了网上说的好几个,但最后只发现Beep Media Player (BMP)可以正常显示中文。
之后又给它安装了wma和ape插件。参看:http://forum.ubuntu.org.cn/viewtopic.php?t=18801

安装mplayer多媒体播放器
参照:http://www.ubuntuforums.org/showthread.php?t=187709 安装了mplayer.
后来才发现可以设置不同的视频驱动,在我的电脑上选gl,gl2驱动后画质最好。但还是比不上Windows上的Kmplayer。功能也远没有 kmplayer丰富,虽然这个播放器是我发现的linux上功能最多的播放器。(参看在linux下用mplayer播放带字幕的电影

安装realplayer
mplayer在播放rmvb文件时不能用鼠标拖放进度,所以决定安装一个realplayer. 用real官方网站(http://www.real.com/linux?pcode=rn&;am)下载了 realpalyer10.0.7.bin, 按照官方说明安装好了,但却死活不能启动, 后来看到
http://forum.ubuntu.org.cn/viewtopic.php?t=14108
才解决了问题。

安装IE
听说工商银行的电子银行只能通过IE访问,我一直很惦记这个问题,再说IE也可以调试网页,所以安装它很有必要。
IE好像没有linux版本,所以只能通过wine虚拟。
我参看:
http://www.tatanka.com.br/ies4linux/page/Installation:Ubuntu
安装,过程很简单。通过wine虚拟出来的IE界面差得一塌糊涂。

安装词典stardict

http://stardict.sourceforge.net/
下载并安装了星际译王,又将windows下的词典文件复制到/usr/share/stardict/dic/目录下。 郁闷的是直到重启系统后它才能找到词典文件。。。

虚拟光驱
据说在linux可以直接使用
sudo mount -o loop /path/filename.iso /media/cdrom
挂接iso文件,而bin文件要转成iso文件,不知道nrg文件要怎么办。

文字编辑
gedit好像是gnome上的记事本。不经意间我发现经常用它。
一般的网页或程序在Windows我用EditPlus编辑,很是顺手。所以在linux上我希望能找个类似编辑器。我安装试用了很多个。
Emacs强大得让我一头水雾。。。一般我不打开它。
BlueFish感觉不错,但好像没有在search in files的重要功能。
SciTE我找不到将编辑区字体设置为18的选项,对我的眼睛不好。
最后找到一个还可以接受的jEdit。
更新:后来没有使用jEdit。日常就使用勉强可以使用的gedit,写代码时就用aptana。

安装beryl
这个能给带来超酷的桌面效果,据说比vista的动画桌面有过之而无不及。
http://www.youtube.com/watch?v=gpOz8duTh-4

我是照:
http://wiki.beryl-project.org/wiki/Install_Beryl_on_Ubuntu_Edgy_with_XGL
安装的。
安装好后要重新启动系统才能打开效果。
虽然感觉很爽,但我还是不太满意。现在我还不知道如何让桌面有雨点下落。。。
更新:后来没有安装beryl,因为不稳定,也点资源,更重要的是不实用。

安装mysql数据库和ruby on rails环境
安装mysql很简单,系统带有。
参照
http://wiki.rubyonrails.com/rails/pages/RailsOnUbuntu
安装ruby on rails的环境也很简单。

ruby on rails编辑环境
在windows上一直使用radrails(http://www.radrails.org/),我一直希望在linux上能找到一个类似的替代品,所以当我发现radrails竟然有linux版本时,我高兴极了。这个软件下载解压 后就可以使用了。
更新:现在使用更名之后的aptana了。

移植mysql数据文件
在原来windows系统下导出数据文件
mysqldump -h host -u user -p database > dump_file
然后在linux上创建一个数据库,将数据文件导入
mysql -h host -u user -p database < dump_file

安装Firestarter防火墙管理软件
Ubuntu内置集成有iptables防火墙,但管理比较麻烦,于是我安装了firestarter,并开通了BT和aMule软件的相应端口。

更新内容:
Google Earth
Google Earth有linux版本。很好玩的东西。

文件管理器
我一直用PCMan File Manager代替系统默认的Nautilus。感觉前者速度更快,操作更方便。缺点是不是很稳定,偶尔会自动关闭。

虚拟机
VirtualBox
刚开始安装了一个VMware,后来果然证实没有VirtualBox速度快。在VBox里面安装的Windows XP上安装QQ要在安装完成之后删除一两个文件才能启动。

Easy Wine
很方便的Wine虚拟机。

现在我基本上可以在linux上完成windows上的一切工作和娱乐项目了。

总体感受:
linux的实用优点:
1.linux是一个更free的系统,很多功能可以定制。
2.在开启多个程序后,linux上反应速度比windows快。
3.因为很少病毒,所以没有安装杀毒软件,这点比Windows好多了。(但要是Linux真的流行起来,可能病毒也会增加的。这是以后的,当问题产生问题时才是问题,呵呵。)

linux的缺点:
1.linux是个更free的系统,这意味着更多的问题要亲手解决。。。
2.linux上的工具还是比不是windows上的完全。
linux上的mplayer没有windows上的kmplayer强大实用
linux平台没有自己很喜欢的EditPlus替代编辑器。
linux上不能使用完整的QQ,旺旺聊天工具等

忙了四天,终于配置好了系统。俗话说开头万事难,以后在使用上应该不会出现太多的问题了,即使有,网上也有好些好心人帮忙。
我相信自己能从这开始,坚持使用linux操作系统。

更新:
Linux已经用了8个多月,总得来说感觉不错。以后也许不会再有可能转到Windows平台了。

发表在 站长文档 | 4 条评论

SEO要点

1.选对关键词(a.关键词和网站相关;b.关键词是网友常用的搜索词)
2.域名带关键词
3.网站名带关键词
4.页面title带关键词
5.页面h1带关键词

6.正文首行带关键词
7.正文10%内容为关键词
8.引用外相关链接带关键词
9.页面内容SE可读
10.100个PR高(5以上)的页面引用目标页面、首页
11.页面内容独特

根本原则:
1.不要骗用户这是个好站
2.不要骗SE这是个差站

发表在 站长文档 | 留下评论

Learning Javascript 3

with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"

Chapter 3. Language Essentials

Arrays
var newCars = new Array("Toyota", "Honda", "Nissan");
newCars[2] returns "Nissan"

Loop
     for (var i=0; i<24; i++) {
        var newNum = Math.floor(Math.random() * 75) + 1;

        document.getElementById("square"  + i).innerHTML = newNum;
     }

var newNum;
     do {
        newNum = colBasis + getNewNum() + 1;
     }
     while (usedNums[newNum]);
remember that the do block of code always gets executed, whether the while check evaluates to true or false.

switch/case
function saySomething() {
     switch(this.value) {
        case "Lincoln":
           alert("Four score and seven years ago…");
           break;
        case "Kennedy":
           alert("Ask not what your country can do for you…");
           break;
        case "Nixon":
           alert("I am not a crook!");
           break;
        default:
     }
}
we've done everything we want to do, and so we want to get out of the switch. In order to do that, we need to break out. Otherwise, we'll execute all of the code below, too.
The default section is where we end up if our switch value didn't match any of the case values. The default block is optional, but it's always good coding practice to include it, just in case (so to speak).

Detecting Objects
if (document.getElementById) {
 xxxxxxxxxxxxx
}
 else {
        alert("Sorry, your browser doesn't support this script");
}

browser detect
Apple's Safari browser claims that it is a Mozilla browser, even though it is not. And some browsers, such as Safari and Opera, allow you to set which browser you want it to report itself as.
The same goes for attempting to detect which version of javascript a browser supports. We strongly suggest that you do not use these detection methods, and use object detection instead.

try/throw/catch
function initAll() {
     var ans = prompt("Enter a number","");
     try {
        if (!ans || isNaN(ans) || ans<0) {
            throw new Error("Not a valid number");
        }
        alert("The square root of " + ans + " is " + Math.sqrt(ans));
     }
     catch (errMsg) {
        alert(errMsg.message);
     }
}

Once an error is thrown, javascript jumps out of the TRy block and looks for a corresponding catch statement. Everything between here and there is skipped over.
If no error was thrown, the code inside the catch will never be executed.

This's the end of my learning javascript program.

发表在 站长文档 | 留下评论

Learning JavaScript 2

with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"

Chapter 2. Start Me Up!
Scripts can be put in one of two places on an HTML page: between the <head> and </head> tags (called a header script), or between the <body> and </body> tags (a body script).
        <script language="javascript" type="text/javascript">
          document.write("Hello, world!");
       </script>

internal scripts

external script, a separate file that just contains javascript.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
     <title>My second script</title>
     <script language="javascript" type="text/javascript" src="script02.js">
     </script>
</head>
<body bgcolor="#FFFFFF">
     <h1 id="helloMessage">
     </h1>
</body>
</html>

script02.js:
window.onload = writeMessage;
// Do this when page finishes loading
/*
a function shown with parentheses means that the function is being called, right then and there. When it's without parentheses, (as it is here) we're assigning it to the event handler, to be run later when that event happens.
*/
function writeMessage() {
     document.getElementById("helloMessage"). innerHTML = "Hello, world!";
}

<noscript>
<noscript>
     <h2>This page requires javascript.</h2>
</noscript>

On non-javascript browsers, a message appears saying that this page requires javascript.

confirm() & alert()
if (confirm("Are you sure you want to do that?")) {
     alert("You said yes");
}
else {
     alert("You said no");
}

condition
(condition) ? truePart : falsePart;
like:
myNewVariable = (condition) ?
truevalue : falsevalue;
or
if (condition) {
        truePart;
}
else {
        falsePart;
}

prompt()
var ans = prompt("Are you sure you want to do that?","");
if (ans) {
     alert("You said " + ans);
}
else {
     alert("You refused to answer");
}
 If a variable is created inside a function, other functions don't have access to it, as it's local to that function. If it's created outside any function, it's global, and everything has access to it.

redirect
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
     <title>Welcome to our site</title>
     <script src="script07.js" type="text/javascript" language="javascript">
     </script>
</head>
<body bgcolor="#FFFFFF">
     <h2 align="center">
         <a href="htmlpage.html" id="redirect"> Welcome to our site… c'mon in!</a>
     </h2>
</body>
</html>

window.onload = initAll;
function initAll() {
     document.getElementById("redirect"). onclick = initRedirect;
}
function initRedirect() {
     window.location = "jspage.html";
     return false; //The return false says to stop processing the user's click, so the href page doesn't get loaded.
}
On first glance, we might think that we could just set the onclick handler globallythat is, as the page is loadingbut we can't. There's a chance, particularly for a large and complex page, that the browser will not yet have come across that redirect id, and if that happens, javascript won't be able to assign the onclick handler. Instead, we have to wait until the page has completed loading, and that's done via onload.

action after the user clicks a link
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
      <title>Welcome to our site</title>
      <script src="script08.js" type="text/javascript" language="javascript">
      </script>
</head>
<body bgcolor="#FFFFFF">
      <h2 align="center">
        Hey, check out <a href="
http://www.pixel.mu/" id="redirect">my cat's Web site</a>.
      </h2>
</body>
</html>

window.onload = initAll;

function initAll() {
     document.getElementById("redirect"). onclick = initRedirect;
}

function initRedirect() {
     alert("We are not responsible for the content of pages outside our site");
     window.location = this; //THIS!!!
  /*The javascript keyword this allows the script to pass a value to a function, solely based on the context where the keyword is used.*/
     return false;
}

document.referrer
A referrer page is the page that the user was viewing before the current page, or, in other words, the page the user came from.
function writeMessage() {
     if (document.referrer != "") {
         document.getElementById("referrerMsg"). innerHTML = "I hope you like this page
better than " + document.referrer;
     }
}

Unobtrusive scripting: An approach to scripting Web pages using javascript, in which the behavior of the Web page is kept separate from its content, that is, the HTML is in one file, and the javascript is in another. Additionally, the term "unobtrusive scripting" is used when code is written such that visitors without javascript (or with less-capable browsers) get all the functionality of a site, just with a less-rich user experience.

And finally, this being the real world, we also know that sometimes the simplest way to hammer in a nail is to grab a rock and pound the nail into the wall. This, for instance, is why we used innerHTML back in Script 2.3, even though it's not part of the W3C DOM.

发表在 站长文档 | 留下评论

Learning Javascript

with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"
By Tom Negrino, Dori Smith
target browsers:
Internet Explorer 6 or later; Firefox 1.0 or later; Netscape 7 or later; all versions of Safari; and Opera 7 or later.

Chapter 1. Getting Acquainted with javascript

What javascript Is
Despite the name, javascript and Java have almost nothing to do with one another.

With Java, a descendant of the C and C++ programming languages, programmers can create entire applications and control consumer electronic devices.
Microsoft dropped Sun's Java from Windows altogether, after creating its own Java-like language, C#.
If javascript isn't related to Java, then why do they have such similar names? It's another example of one of the computer industry's most annoying traits: the triumph of marketing over substance.
and ever since then, writers like us have made good money explaining that javascript and Java are very different things.
This Microsoft version of javascript is called JScript.

What javascript Can Do
 A rollover is an image that changes when you move the mouse pointer over it.
javascript has some limitations built-in, mostly for security reasons:
 1.javascript does not allow the reading or writing of files on client machines. The only exception is that javascript can write to the browser's cookie file.
 2.javascript does not allow the writing of files on server machines.
 3.javascript cannot close a window that it hasn't opened.
 4.javascript cannot read information from an opened Web page that came from another server.

What Is Ajax?
Ajax is shorthand for Asynchronous javascript and XML.
In the larger scheme of things, what's generally referred to as Ajax is the combination of these technologies:
 XHTML
 CSS (Cascading Style Sheets)
 The DOM (Document Object Model) accessed using javascript
 XML, the format of the data being transferred between the server and the client
 XMLHttpRequest to retrieve data from the server

javascript is an object-oriented language
Objects
Properties, Objects have properties.
Methods, The things that objects can do are called methods.
dot syntax
 document.images.name
 forms.elements.radio.click()

The representation of the objects within the document is called the Document Object Model (DOM).
Each of the objects on the tree is also called a node of the tree. If the node contains an HTML tag, it's referred to as an element node. Otherwise, it's referred to as a text node.
Events are actions that the user performs while visiting your page. javascript deals with events using commands called event handlers.
The 12 most common javascript event handlers :
 onabort
 onblur
 onchange
 onclick
 onerror
 onfocus
 onload
 onmouseover
 onmouseout
 onselect
 onsubmit
 onunload

value Types:
 Number
 String
 Boolean
 Null
 Object
 Function
value returned by a function
Variable names cannot contain spaces or other punctuation, or start with a digit. They also can't be one of the javascript reserved words.  javascript is case sensitive.
Operators:
 x + y (Numeric)
 x + y (String)
 x – y
 x * y
 x / y

 x % y Modulus of x and y (i.e., the remainder when x is divided by y)
 x++, ++ x
 (if x is 5, y=x++ results in y set to 5 and x set to 6, while y=++x results in both x and y set to 6. The operator – (minus sign) works similarly.)
 x–, –x
 -x

Assignments:
 x = y
 x += y

  Same as x = x + y
 x -= y
 x *= y
 x /= y
 x %= y

Comparisons:
 x == y
 x != y
 x > y

 If you are comparing strings, be aware that "a" is greater than "A" and that "abracadabra" is less than "be".
 x > = y
 x < y
 x <= y
 x && y
 x || y
 !x

Writing javascript-Friendly HTML
Structure, presentation, and behavior
When split up this way, your sites will contain three types of text files:
 XHTML: content and structure
 CSS: appearance and presentation
 javascript: behavior
CSS:
A <div> is a block-level element, that is, there's a physical break between it and the elements above and below it. A <span> isn't block-level; instead, it's inline, so you can apply it to, for instance, a single phrase within a sentence.
A class identifies an element that you may want to use more than once. An id identifies an element that is unique to that document.

发表在 站长文档 | 留下评论

如何将使用Access数据库文件的ASP程序转向SQL数据库

如何将使用access数据库文件的asp程序转向sql数据库

因为blog的access数据库文件经常出问题, 于是昨晚将blog转向了sql数据库. 网上找了一些文章, 现在经合自己的经验, 把实际操作要点写下来.

一.数据库转换问题
1.用SQL Server新建一个数据库, 然后将mdb文件中的access数据导入(import)这个新建的数据库.
2.access数据库原来自动增长的ID在SQL中要重新设置,设置为“标识”(identity).
3.access表内数据类型"是/否",到了sql server的表内就是 bit (not null),有可能一些true/false类型不能使用,要变为1/0。
4.原来的默认值都丢失了.主要是数字类型和日期类型.
5.转化时,跟日期有关的字段,SQL SERVER默认为smalldatetime型,我们最好将它变为datetime型,因为datetime型的范围比smalldatetime型大。有时用smalldatetime型时,转化失败,而用datetime型时,转化成功。
6.在mssql server中,有许多保留字。mssql在导入的时候,会自动给这些字段(包括数据库中的表名)加上[字段名],因此,你必须修改你的脚本,把相应的字段名字(或者表名字)加上中括号,或改变字段名字为不是mssql的保留字.最好在有可能和系统关键字的地方使用[和]将他包围起来,以避免在移植过程中出现的运行错误问题  
7.CursorType要改成1,也就是打开数据库时要给出第一个数字参数为1,否则记录可能 显示不完整 
8.备注类型要通过cast(column as varchar)来使用 

二.asp数据库连接语句修改
以下假设strConn为连接字符串变量名.
由原来strConn="Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(数据库文件路径)
改为:strConn="Provider=SQLOLEDB;Data Source=’数据库所在服务器IP(本地为127.0.0.1)’;Initial Catalog=’数据库名’;User ID=’数据库用户名’;Password=’数据库用户密码’;" 

三.查寻语句问题(注意以下适用的是sql查寻语句中的修改原则, 不要修改查寻语句外的asp语句)
1.所有的sql语句中的now(),time(),date()必须换成getdate()。
2.isnull(rowname)要改成rowname = null 
3.所有datediff(’d’, time1, time2)要改成datediff(day, time1, time2) ,所有datediff(’ww’, time1, time2)要改成datediff(week, time1, time2)  (或datediff("d", time1, time2)要改成datediff(day, time1, time2) ,datediff("ww", time1, time2)要改成datediff(week, time1, time2)  )
4.“DELETE * FROM ……”要改为“DELETE FROM ……” 例如:在对ACCESS数据库进行删除纪录时用:"delete * from user where id=10",而对SQL SERVER数据库进行删除是用:"delete user where id=10". 
5.access里面除法可以使用"\"或者"/",MSSQL里面只能使用"/"
6.SQL语句中Like后面字符串的通配符’*'要改成’%'。
7.access查询通过cdate构造日期,sql server内是convert(datetime,…), convert使用方法见下文.
8.在对ACCESS数据库处理中,sql语句中直接可以用一些VB的函数,像instr()函数,而对SQL SERVER数据库处理中不能使用这类函数(instr()可用charindex函数代替,方法见下文)。 
9.在access的sql语句中的时间使用变量查询的时候,一般使用"select * from aaaa while time=#"&变量名&"#",在mssql中的语法是“select * from aaaa while time=’"&变量名&"’"”。不然有可能rs.update失败,修改成update 表名 set 字段=‘值’ 这样通过(遇到的情况,提示为: Microsoft OLE DB Provider for SQL Server 错误 ’80040e38’  )

SQL中CONVERT转化函数的用法

CONVERT的使用方法:

////////////////////////////////////////////////////////////////////////////////////////

格式:
CONVERT(data_type,expression[,style])

说明:
此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,char,varchar)
相互转换的时候才用到.

例子:
SELECT CONVERT(varchar(30),getdate(),101) now
结果为
now
—————————————
09/15/2001

/////////////////////////////////////////////////////////////////////////////////////

style数字在转换时间时的含义如下

————————————————————————————————-
Style(2位表示年份) | Style(4位表示年份) | 输入输出格式 
————————————————————————————————-
- | 0 or 100 | mon dd yyyy hh:miAM(或PM) 
————————————————————————————————-
1 | 101 | mm/dd/yy 
————————————————————————————————-
2 | 102 | yy-mm-dd 
————————————————————————————————-
3 | 103 | dd/mm/yy 
————————————————————————————————-
4 | 104 | dd-mm-yy 
————————————————————————————————-
5 | 105 | dd-mm-yy 
————————————————————————————————-
6 | 106 | dd mon yy 
————————————————————————————————-
7 | 107 | mon dd,yy 
————————————————————————————————-
8 | 108 | hh:mm:ss 
————————————————————————————————-
- | 9 or 109 | mon dd yyyy hh:mi:ss:mmmmAM(或PM)
————————————————————————————————-
10 | 110 | mm-dd-yy 
————————————————————————————————-
11 | 111 | yy/mm/dd 
————————————————————————————————-
12 | 112 | yymmdd 
————————————————————————————————-
- | 13 or 113 | dd mon yyyy hh:mi:ss:mmm(24小时制) 
————————————————————————————————-
14 | 114 | hh:mi:ss:mmm(24小时制) 
————————————————————————————————-
- | 20 or 120 | yyyy-mm-dd hh:mi:ss(24小时制, 应该和now()生成的日期格式相同) 
————————————————————————————————-
- | 21 or 121 | yyyy-mm-dd hh:mi:ss:mmm(24小时制) 
————————————————————————————————-

 

使用charindex函数代替   
    
  CHARINDEX   
  返回字符串中指定表达式的起始位置。     
    
  语法   
  CHARINDEX   (   expression1   ,   expression2   [   ,   start_location   ]   )     
    
  参数   
  expression1   
    
  一个表达式,其中包含要寻找的字符的次序。expression1   是一个短字符数据类型分类的表达式。   
    
  expression2   
    
  一个表达式,通常是一个用于搜索指定序列的列。expression2   属于字符串数据类型分类。   
    
  start_location   
    
  在   expression2   中搜索   expression1   时的起始字符位置。如果没有给定   start_location,而是一个负数或零,则将从   expression2   的起始位置开始搜索。   
    
  返回类型   
  int   
    
  注释   
  如果   expression1   或   expression2   之一属于   Unicode   数据类型(nvarchar   或   nchar)而另一个不属于,则将另一个转换为   Unicode   数据类型。   
    
  如果   expression1   或   expression2   之一为   NULL   值,则当数据库兼容级别为   70   或更大时,CHARINDEX   返回   NULL   值。当数据库兼容级别为   65   或更小时,CHARINDEX   仅在   expression1   和   expression2   都为   NULL   时返回   NULL   值。     
    
  如果在   expression2   内没有找到   expression1,则   CHARINDEX   返回   0。   

发表在 站长文档 | 留下评论