个人对ASP中的split的简单理解。

大家有没有碰到过要想取一字符串里的某些值而无从下手?有没有觉得看书或教材对split的写法糊里糊涂……如果有此疑问的话,请看下面我对例子的解释,相信您会对这个有一定的了解。
例如我想取得一个ftp里的用户名及密码(服务器等)值(用IE当FTP时或从表中取出FTP的值)。
下面是我的解决思路:
设url为收到的URL值,这里指:

  1. url=ftp://username:password@server,

请注意这句话的规律
我想大家都看清楚这个URL里的规律了吧,就是各个部分都被”:”给区分成三个部分,即:ftp、//username、password@server
首先将这个URL的各个部分区分开来,用split(url, “:”)
以下是具体的代码:

  1. parts = split(url, ":") '此时parts就有三部分,parts(0)=ftp,parts(1)=//username,parts(2)=password@server'接下来剔除没有用到的信息'由于只取username,所以其中parts(0)跟parts(2)是无用的,直接不引用!newname=replace(parts(1), "//", "") '去除//符号,因为这不是username里的内容'此时的newname既为用户名。

以上是只取用户名的代码,如果你要再取密码的话,可以参考下面。

由于用户名是属于parts(2)里的,而且包含服务器的信息,如果不取服务器,则:newpass = left(parts(2), instr(parts(2),”@”)-1) ‘取值到@之前的位数。此时的newpass取为密码

以上代码为不取服务器地址的代码,如果有取服务器的话,其实也是很简单的

  1. newparts=split(parts(2),"@") '此时newparts分成两部分:newparts(0)为密码,即password;newparts(1)则为服务器地址,即server'如果要输出密码的的话,直接response.write newparts(0)就可以了,服务器就newparts(1)

后话,对于要取一字符串中的某些字符或部分,只要抓住规律,再加上用split就可以很好做成各种效果。写此文,希望对大家的学习有所帮助,同时也希望大家能够指点一二!

文章系统中“上篇、下篇”效果的制作

以前曾经参考过一个网站的源码,是使用ID+1和ID-1的办法来判断上下篇的。在实际使用过程中,发现一个问题:当删除数据库中的一篇文章时,就会造成ID不连续,如果用ID+1和ID-1来判断就会出现找不到记录。所以程序并不是非常的完美。
  在我们所介绍的ASP代码中,是通过查询大于当前ID的第一条记录来找出下一篇的ID,查询小于当前ID的第一条记录来找出上一篇的ID,这样就算ID不连续也可以正常显示了。(程序代码也是参阅过经典论坛相关贴子提示所制作的)
查看全文 »

鼠标旁边的提示信息,类似与163登录后的页面提示效果

  1. <a href="#" title="这是提示">tip</a>
  2. <script Language="JavaScript">
  3. //***********默认设置定义.*********************
  4. tPopWait=50;//停留tWait豪秒后显示提示。
  5. tPopShow=5000;//显示tShow豪秒后关闭提示
  6. showPopStep=20;
  7. popOpacity=99;
  8. //***************内部变量定义*****************
  9. sPop=null;
  10. curShow=null;
  11. tFadeOut=null;
  12. tFadeIn=null;
  13. tFadeWaiting=null;
  14. document.write("<style type='text/css'id='defaultPopStyle'>");
  15. document.write(".cPopText {  background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
  16. document.write("</style>");
  17. document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
  18.  
  19. function showPopupText(){
  20. var o=event.srcElement;
  21. MouseX=event.x;
  22. MouseY=event.y;
  23. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  24.         if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  25. if(o.dypop!=sPop) {
  26. sPop=o.dypop;
  27. clearTimeout(curShow);
  28. clearTimeout(tFadeOut);
  29. clearTimeout(tFadeIn);
  30. clearTimeout(tFadeWaiting);
  31. if(sPop==null || sPop=="") {
  32. dypopLayer.innerHTML="";
  33. dypopLayer.style.filter="Alpha()";
  34. dypopLayer.filters.Alpha.opacity=0;
  35. }
  36. else {
  37. if(o.dyclass!=null) popStyle=o.dyclass
  38. else popStyle="cPopText";
  39. curShow=setTimeout("showIt()",tPopWait);
  40. }
  41. }
  42. }
  43. function showIt(){
  44. dypopLayer.className=popStyle;
  45. dypopLayer.innerHTML=sPop;
  46. popWidth=dypopLayer.clientWidth;
  47. popHeight=dypopLayer.clientHeight;
  48. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
  49. else popLeftAdjust=0;
  50. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
  51. else popTopAdjust=0;
  52. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  53. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  54. dypopLayer.style.filter="Alpha(Opacity=0)";
  55. fadeOut();
  56. }
  57. function fadeOut(){
  58. if(dypopLayer.filters.Alpha.opacity<popOpacity) {
  59. dypopLayer.filters.Alpha.opacity+=showPopStep;
  60. tFadeOut=setTimeout("fadeOut()",1);
  61. }
  62. else {
  63. dypopLayer.filters.Alpha.opacity=popOpacity;
  64. tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  65. }
  66. }
  67. function fadeIn(){
  68. if(dypopLayer.filters.Alpha.opacity>0) {
  69. dypopLayer.filters.Alpha.opacity-=1;
  70. tFadeIn=setTimeout("fadeIn()",1);
  71. }
  72. }
  73. document.onmouseover=showPopupText;
  74. </script>

如何定时运行ASP文件 – blueidea.com

看到觉得蛮实用的,就摘录下来了,原文地址是《如何定时运行ASP文件
————————————————–
在一定的时候,要定时的运行某个ASP文件去执行一个任务,如一个工厂在早上9点钟要采集所有的电表的读数,当然这要通过IN SQL连接到各个电表中,我们现在就是用一个ASP文件把IN SQL中表的读数再集中到MS SQL中。
 
可能你看到的定时运行ASP文件的方法有多种,不过我现在要说的是一种简单的方法,利用计划任务就可简单的实现。
 
首先,你要写一个js或者vbs文件来调用你所有执行的ASP。下面是js和vbs文件的代码,你可以任选一个,执行效果是一样的。

  1. 'CODE BY 小荷 aston314@sohu.com
  2. 'Create an instance of IE
  3. Dim IE
  4. Set IE = CreateObject("InternetExplorer.Application")
  5.  
  6. '运行你的 URL
  7.  
  8. ie.navigate("http://www.blueidea.com/")
  9. ie.visible=1
  10.  
  11. 'Clean up...
  12. Set IE = Nothing

你可以取任何名称,但后缀名一定要是vbs,在这里我们取名do.vbs。

  1. //CODE BY 小荷 aston314@sohu.com
  2. // Create the HTML message to display.
  3. var html = "";
  4.     html += "<html><head><title>运行窗口</title></head><body>";
  5.         html += "<font face=verdana></font>";
  6.         html += "</body></html>";
  7.  
  8.  
  9. // Create Internet Explorer Object
  10. ie = new ActiveXObject("InternetExplorer.Application");
  11.  
  12. // Define how the window should look
  13. ie.left       = 50;
  14. ie.top        = 50;
  15. ie.height     = 510;
  16. ie.width      = 470;
  17. ie.menubar    = 0;
  18. ie.toolbar    = 0;
  19.  
  20. // Set the browser to a blank page
  21. ie.navigate("http://www.blueidea.com/");
  22.  
  23. // Show the browser
  24. ie.visible=1;
  25.  
  26. // Open a stream and write data.
  27. //ie.document.open;
  28. //ie.document.write( html );
  29. //ie.document.close;

你也可以取任何名称,但后缀名一定要是js,在这里我们取名do.js。

这里不对文件中的代码进行解说。

只要把上面文件中的所有 http://www.blueidea.com/ 换成你要执行的ASP文件的URL地址就可以了。这里是URL地址,而不是绝对地址。

然后打开 WINDOWS 的任务计划,就象选择任何可执行文件一样选择上面一个do.js或者do.vbs文件所在的位置,设定执行时间等,确定就可以了。

然后这个ASP文件就可以被任务计划定时的运行了,简单吧。

就如开头所说的,任务计划就可以在早上9点,执行这个ASP文件,把电表的读数收集到 MS SQL 中了。

逐步闪烁的文字

  1. <script Language="JavaScript">
  2. <!--
  3. if(navigator.appVersion.charAt(0)>=4 && (navigator.appVersion).indexOf("MSIE")!=-1) isIE4 = true;
  4. else isIE4 = false;
  5. function textAnima_color2(id,n) {
  6. el = document.all.item(id,n);
  7. charColor = el.getAttribute("SET_COLOR");
  8. cur = el.getAttribute("CURRENT_CHAR");
  9. if(cur=="") cur = 0;
  10.  
  11. getHTML= el.getAttribute("SET_TEXT");
  12. if(getHTML == "") {
  13. getHTML = el.innerText;
  14. el.setAttribute("SET_TEXT",getHTML);
  15. }
  16.  
  17. bef_t = getHTML.substring(0,cur); ;
  18. aft_t = getHTML.substring(eval(cur)+1,getHTML.length);
  19. cur_t = getHTML.substr(cur,1);
  20. cur_t = cur_t.fontcolor(charColor);
  21. el.innerHTML = bef_t + cur_t + aft_t;
  22.  
  23. cur++;
  24. if(cur > getHTML.length) cur=0;
  25. el.setAttribute("CURRENT_CHAR",cur);
  26. getT = el.getAttribute("SET_TIME");
  27. if(getT=="") getT = 100;
  28. setTimeout("textAnima_color2('"+id+"',"+n+")",eval(getT));
  29. }
  30.  
  31. if(isIE4) {
  32. window.onload = init;
  33. }
  34.  
  35.  
  36. function init() {
  37. id = "ANIMA_TEXT_COLOR2";
  38. len = document.all.item(id).length;
  39. if(!len) len=1;
  40. for(var i=0;i<len;i++) {
  41. textAnima_color2(id,i);
  42. }
  43. }
  44. //-->
  45. </script>
  46. <b><span style="font-size:14pt;color=red;font-family:新細明體";
  47. id="ANIMA_TEXT_COLOR2" SET_COLOR="yellow"
  48. SET_TIME="100" CURRENT_CHAR SET_TEXT>JAVASCRIPT閃爍文字效果!!!</span>

无觅相关文章插件,快速提升流量

« 上一页下一页 »