<Script LANGUAGE="JavaScript">

  var months = new Array("一", "二", "三","四", "五", "六", "七", "八", "九","十", "十一", "十二");


  var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);


  var days = new Array("日","一", "二", "三","四", "五", "六");


  var classTemp;


  var today=new getToday();


  var year=today.year;


  var month=today.month;


  var newCal;


  function getDays(month, year) {


  if (1 == month) return ((0 == year % 4) && (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28;


  else return daysInMonth[month];


  }


  function getToday() {


  this.now = new Date();


  this.year = this.now.getFullYear();


  this.month = this.now.getMonth();


  this.day = this.now.getDate();


  }


  function Calendar() {


  newCal = new Date(year,month,1);


  today = new getToday();


  var day = -1;


  var startDay = newCal.getDay();


  var endDay=getDays(newCal.getMonth(), newCal.getFullYear());


  var daily = 0;


  if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))


  {


  day = today.day;


  }


  var caltable = document.all.caltable.tBodies.calendar;


  var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());


  for (var intWeek = 0; intWeek < caltable.rows.length;intWeek++)


  for (var intDay = 0;intDay < caltable.rows[intWeek].cells.length;intDay++)


  {


  var cell = caltable.rows[intWeek].cells[intDay];


  var montemp=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+1)):(newCal.getMonth()+1);


  if ((intDay == startDay) && (0 == daily)){ daily = 1;}


  var daytemp=daily<10?("0"+daily):(daily);


  var d="<"+newCal.getFullYear()+"-"+montemp+"-"+daytemp+">";


  if(day==daily) cell.className="DayNow";


  else if(intDay==6) cell.className = "DaySat";


  else if (intDay==0) cell.className ="DaySun";


  else cell.className="Day";


  if ((daily > 0) && (daily <= intDaysInMonth))


  {


  cell.innerText = daily;


  daily++;


  } else


  {


  cell.className="CalendarTD";


  cell.innerText = "";


  }


  }


  document.all.year.value=year;


  document.all.month.value=month+1;


  }


  function subMonth()


  {


  if ((month-1)<0)


  {


  month=11;


  year=year-1;


  } else


  {


  month=month-1;


  }


  Calendar();


  }


  function addMonth()


  {


  if((month+1)>11)


  {


  month=0;


  year=year+1;


  } else


  {


  month=month+1;


  }


  Calendar();


  }


  function setDate()


  {


  if (document.all.month.value<1||document.all.month.value>12)


  {


  alert("月的有效范围在1-12之间!");


  return;


  }


  year=Math.ceil(document.all.year.value);


  month=Math.ceil(document.all.month.value-1);


  Calendar();


  }


  </Script>


  <Script>


  function buttonOver()


  {


  var obj = window.event.srcElement;


  obj.runtimeStyle.cssText = "background-color:#FFFFFF";


  // obj.className="Hover";


  }


  function buttonOut()


  {


  var obj = window.event.srcElement;


  window.setTimeout(function(){obj.runtimeStyle.cssText = "";},300);


  }


  </Script>


  <Style>


  Input {font-family: verdana;font-size: 9pt;text-decoration: none;background-color: #FFFFFF;height: 20px;border: 1px solid #666666;color:#000000;}


  .Calendar {font-family: verdana;text-decoration: none;width: 170;background-color: #C0D0E8;font-size: 9pt;border:0px dotted #1C6FA5;}


  .CalendarTD {font-family: verdana;font-size: 7pt;color: #000000;background-color:#f6f6f6;height: 20px;width:11%;text-align: center;}


  .Title {font-family: verdana;font-size: 11pt;font-weight: normal;height: 24px;text-align: center;color: #333333;text-decoration: none;background-color: #A4B9D7;border-top-width: 1px;border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-bottom-style:1px;border-top-color: #999999;border-right-color: #999999;border-bottom-color: #999999;border-left-color: #999999;}


  .Day {font-family: verdana;font-size: 7pt;color:#243F65;background-color: #E5E9F2;height: 20px;width:11%;text-align: center;}


  .DaySat {font-family: verdana;font-size: 7pt;color:#FF0000;text-decoration: none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}


  .DaySun {font-family: verdana;font-size: 7pt;color: #FF0000;text-decoration: none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}


  .DayNow {font-family: verdana;font-size: 7pt;font-weight: bold;color: #000000;background-color: #FFFFFF;height: 20px;text-align: center;}


  .DayTitle {font-family: verdana;font-size: 9pt;color: #000000;background-color: #C0D0E8;height: 20px;width:11%;text-align: center;}


  .DaySatTitle {font-family: verdana;font-size: 9pt;color:#FF0000;text-decoration: none;background-color:#C0D0E8;text-align: center;height: 20px;width: 12%;}


  .DaySunTitle {font-family: verdana;font-size: 9pt;color: #FF0000;text-decoration: none;background-color: #C0D0E8;text-align: center;height: 20px;width: 12%;}


  .DayButton {font-family: Webdings;font-size: 9pt;font-weight: bold;color: #243F65;cursor:hand;text-decoration: none;}


  </Style>


  <table border="0" cellpadding="0" cellspacing="1" class="Calendar" id="caltable">


  <thead>


  <tr align="center" valign="middle">


  <td colspan="7" class="Title">


  <a href="javaScript:subMonth();" title="上一月" Class="DayButton">3</a> <input name="year" type="text" size="4" maxlength="4" onkeydown="if (event.keyCode==13){setDate()}" onkeyup="this.value=this.value.replace(/[^0-9]/g,')" onpaste="this.value=this.value.replace(/[^0-9]/g,')"> 年 <input name="month" type="text" size="1" maxlength="2" onkeydown="if (event.keyCode==13){setDate()}" onkeyup="this.value=this.value.replace(/[^0-9]/g,')" onpaste="this.value=this.value.replace(/[^0-9]/g,')"> 月 <a href="JavaScript:addMonth();" title="下一月" Class="DayButton">4</a>


  </td>


  </tr>


  <tr align="center" valign="middle">


  <Script LANGUAGE="JavaScript">


  document.write("<TD class=DaySunTitle id=diary >" + days[0] + "</TD>");


  for (var intLoop = 1; intLoop < days.length-1;intLoop++)


  document.write("<TD class=DayTitle id=diary>" + days[intLoop] + "</TD>");


  document.write("<TD class=DaySatTitle id=diary>" + days[intLoop] + "</TD>");


  </Script>


  </TR>


  </thead>


  <TBODY border=1 cellspacing="0" cellpadding="0" ID="calendar" ALIGN=CENTER ONCLICK="getDiary()">


  <Script LANGUAGE="JavaScript">


  for (var intWeeks = 0; intWeeks < 6; intWeeks++)


  {


  document.write("<TR style='cursor:hand'>");


  for (var intDays = 0; intDays < days.length;intDays++) document.write("<TD class=CalendarTD onMouseover='buttonOver();' onMouseOut='buttonOut();'></TD>");


  document.write("</TR>");


  }


  </Script>


  </TBODY>


  </TABLE>


  <Script LANGUAGE="JavaScript">


  Calendar();


  </Script>

Posted on November 30, 2006 10:12 AM | | Comments (0) | TrackBacks (0)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Canlender--JavaScript</title>
<style>
td {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
}

</style>

</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="180">
<tr><td id=cc>
</td></tr></table>
</body>
<script language="JavaScript">
function RunNian(The_Year)
{
 if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))
  return true;
 else
  return false;
}
function GetWeekday(The_Year,The_Month)
{
 
 var Allday;
 Allday = 0;
 if (The_Year>2000)
 {
  
  for (i=2000 ;i<The_Year; i++) 
   if (RunNian(i))
    Allday += 366;
   else
    Allday += 365;
  for (i=2; i<=The_Month; i++)
  {
   switch (i)
   {
    case 2 :
     if (RunNian(The_Year))
      Allday += 29;
     else
      Allday += 28;
     break;
    case 3 : Allday += 31; break;
    case 4 : Allday += 30; break;
    case 5 : Allday += 31; break;
    case 6 : Allday += 30; break;
    case 7 : Allday += 31; break;
    case 8 : Allday += 31; break;
    case 9 : Allday += 30; break;
    case 10 : Allday += 31; break;
    case 11 : Allday += 30; break;
    case 12 :  Allday += 31; break;
    
   }
   
  }
 }
 
 return (Allday+6)%7;
 

}

function chooseday(The_Year,The_Month,The_Day)
{
 var Firstday;
 var completely_date;
 if (The_Day!=0)
  completely_date = The_Year + "-" + The_Month + "-" + The_Day;
 else
  completely_date = "No Choose";
 //showdate 只是一个为了显示而采用的东西,
 //如果外部想引用这里的时间,可以通过使用 completely_date引用完整日期
 //也可以通过The_Year,The_Month,The_Day分别引用年,月,日
 //当进行月份和年份的选择时,认为没有选择完整的日期
 showdate.innerText = completely_date;
 Firstday = GetWeekday(The_Year,The_Month);
 ShowCalender(The_Year,The_Month,The_Day,Firstday);
 
}

function nextmonth(The_Year,The_Month)
{
 if (The_Month==12)
  chooseday(The_Year+1,1,0);
 else
  chooseday(The_Year,The_Month+1,0);
}

function prevmonth(The_Year,The_Month)
{
 if (The_Month==1)
  chooseday(The_Year-1,12,0);
 else
  chooseday(The_Year,The_Month-1,0);
}

function prevyear(The_Year,The_Month)
{
 chooseday(The_Year-1,The_Month,0);
}

function nextyear(The_Year,The_Month)
{
 chooseday(The_Year+1,The_Month,0);
}

 

 

function ShowCalender(The_Year,The_Month,The_Day,Firstday)
{

 var showstr;
 var Month_Day;
 var ShowMonth;
 var today;
 today = new Date();
 
 
 
 switch (The_Month)
 {
  case 1 : ShowMonth = "January"; Month_Day = 31; break;
  case 2 :
   ShowMonth = "February";
   if (RunNian(The_Year))
    Month_Day = 29;
   else
    Month_Day = 28;
   break;
  case 3 : ShowMonth = "March"; Month_Day = 31; break;
  case 4 : ShowMonth = "April"; Month_Day = 30; break;
  case 5 : ShowMonth = "May"; Month_Day = 31; break;
  case 6 : ShowMonth = "June"; Month_Day = 30; break;
  case 7 : ShowMonth = "July"; Month_Day = 31; break;
  case 8 : ShowMonth = "August"; Month_Day = 31; break;
  case 9 : ShowMonth = "September"; Month_Day = 30; break;
  case 10 : ShowMonth = "October"; Month_Day = 31; break;
  case 11 : ShowMonth = "November"; Month_Day = 30; break;
  case 12 : ShowMonth = "December"; Month_Day = 31; break;
   
 }
 
 
 showstr = "";
 showstr = "<Table cellpadding=0 cellspacing=0 border=1 bordercolor=#999999 width=95% align=center valign=top>";
 showstr +=  "<tr><td width=0 style='cursor:hand' onclick=prevyear("+The_Year+"," + The_Month + ")>&lt;&lt;</td><td width=0>&nbsp;" + The_Year + "&nbsp;</td><td width=0 onclick=nextyear("+The_Year+","+The_Month+")  style='cursor:hand'>&gt;&gt;</td><td width=0 style='cursor:hand' onclick=prevmonth("+The_Year+","+The_Month+")>&lt;&lt;</td><td width=100 align=center>" + ShowMonth + "</td><td width=0 onclick=nextmonth("+The_Year+","+The_Month+")  style='cursor:hand'>&gt;&gt;</td></tr>";
 showstr +=  "<tr><td align=center width=100% colspan=6>";
 showstr +=  "<table cellpadding=0 cellspacing=0 border=1 bordercolor=#999999 width=100%>";
 showstr += "<Tr align=center bgcolor=#999999> ";
    showstr += "<td><strong><font color=#0000CC>日</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>一</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>二</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>三</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>四</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>五</font></strong></td>";
    showstr += "<td><strong><font color=#0000CC>六</font></strong></td>";
 showstr += "</Tr><tr>";
 
 for (i=1; i<=Firstday; i++)
  showstr += "<Td align=center bgcolor=#CCCCCC>&nbsp;</Td>";
 
 for (i=1; i<=Month_Day; i++)
 {
  if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate()))
   bgColor = "#FFCCCC";
  else
   bgColor = "#CCCCCC";
  
  if (The_Day==i) bgColor = "#FFFFCC";
  showstr += "<td align=center bgcolor=" + bgColor + " style='cursor:hand' onclick=chooseday(" + The_Year + "," + The_Month + "," + i + ")>" + i + "</td>";
  Firstday = (Firstday + 1)%7;
  if ((Firstday==0) && (i!=Month_Day)) showstr += "</tr><tr>";
 }
 if (Firstday!=0) 
 {
  for (i=Firstday; i<7; i++)
   showstr += "<td align=center bgcolor=#CCCCCC>&nbsp;</td>";
  showstr += "</tr>";
 }
  
 showstr += "</tr></table></td></tr></table>";
 cc.innerHTML = showstr;  
 

}


</script>

<script language="JavaScript">

 var The_Year,The_Day,The_Month;
 var today;
 var Firstday;
 today = new Date();
 The_Year = today.getYear();
 The_Month = today.getMonth() + 1;
 The_Day = today.getDate();
 Firstday = GetWeekday(The_Year,The_Month);
 ShowCalender(The_Year,The_Month,The_Day,Firstday);
</script>
<div id=showdate></div>
</html>
Posted on November 30, 2006 10:11 AM | | Comments (0) | TrackBacks (0)

1、

<script language="vbscript">
/*利用VBScript构建asc吗和字符串的互转函数*/
Function str2asc(strstr)
 str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
 asc2str = chr(ascasc)
End Function
</script>


<script language="javascript">
/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
  var ret="";
  var strSpecial="!"#$%&'()*+,/:;<=>?[]^`{|}~%";
  for(var i=0;i<str.length;i++){
   var chr = str.charAt(i);
    var c=str2asc(chr);
    tt += chr+":"+c+"n";
    if(parseInt("0x"+c) > 0x7f){
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
    }else{
      if(chr==" ")
        ret+="+";
      else if(strSpecial.indexOf(chr)!=-1)
        ret+="%"+c.toString(16);
      else
        ret+=chr;
    }
  }
  return ret;
}
function UrlDecode(str){
  var ret="";
  for(var i=0;i<str.length;i++){
   var chr = str.charAt(i);
    if(chr == "+"){
      ret+=" ";
    }else if(chr=="%"){
     var asc = str.substring(i+1,i+3);
     if(parseInt("0x"+asc)>0x7f){
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
      i+=5;
     }else{
      ret+=asc2str(parseInt("0x"+asc));
      i+=2;
     }
    }else{
      ret+= chr;
    }
  }
  return ret;
}
</script>

2、

function urlencode(str)
tmp=""
strSpecial="_-.1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i=1 to len(str)
  crt=mid(str,i,1)
  if instr(1,strSpecial,crt,1) then  
   tmp=tmp&crt  
  else
   hexc=hex(asc(crt))
   tmp=tmp&"%"& mid(hexc,1,2)
   if len(hexc)>2 then
    tmp=tmp&"%"& mid(hexc,3,2)
   end if
  end if  
next
urlencode=tmp
end function

3、

<script language="vbscript">

function urlencode(vstrin)
    dim i,strreturn,strSpecial
    strSpecial = " <>""#%{}|^~[]`'&?+"
    strreturn = ""
    for i = 1 to len(vstrin)
        thischr = mid(vstrin,i,1)
        if abs(asc(thischr)) < &hff then
            if instr(strSpecial,thischr)>0 then
                strreturn = strreturn & "%" & hex(asc(thischr))
            else
                strreturn = strreturn & thischr
            end if
        else
            innercode = asc(thischr)
            if innercode < 0 then
                innercode = innercode + &h10000
            end if
            hight8 = innercode '(innercode  and &hff00)' mod &hff
            low8 = innercode and &hff
            strreturn = strreturn & "%" & hex(hight8) &  "%" & hex(low8)
        end if
    next
    urlencoding = strreturn
end function
document.write(urlencode("中文 <>""#%{}|^~[]`'&?+Abc")+"<br>")
</script>

Posted on November 25, 2006 11:52 AM | | Comments (0) | TrackBacks (0)

   为什么要从时间验证的例子开始我们的正则表达之旅呢?首先,因为时间校验比较常用,尤其是日期的验证几乎是每个注册程序都要进行校验的;另外,日期函数相 对来说包含的涉及正则表达式的内容较少,其次字符单一除了数字之外,就是几个很有限的连接连接符号,正则逻辑简单。

    预备知识:
    1.为JavaScript增加函数:熟悉Java的人都是知道,Java所有的方法都是封装在类中的,那么JavaScript实际上类似(注意:我并 没有讨论JavaScript和Java的相关性,只是说道他们的相似性);JavaScript中所有的字符串操作实际上都是在String这个类中, 那么我们要为字符串增加一个日期校验的函数应该来怎么做呢?
     类名.prototype.方法名 = function (){
        /*语句块*/
     }
     比如我们为字符创类增加一个日期校验的方法IsDate:
     String.prototype.IsDate=function(){
     } 
     那么问题来了,这个字符串本身用什么来代表呢?数字面向对象的朋友很快就会想到this,对了就是它;


     2.正则表达式的基本知识:
        /  标识正则表达式的开始位置和基础位置
        ^  表示字符串的开始位置
        $  表示字符串的结束位置
        |  或者
        -  描述该字符串的是由(-)左右连个字符之间的所有字符构成
        {n,m}有n到m个字符串组成

     下面我们就开始日期校验函数的编写
      首先我们分析一个完整日期的构成,比如2005-9-13
      ?年份是后4位数字构成
      ?月份是由1-12的数字构成
      ?日期是由1-31的数字构成
      ?年份可以被四整除为闰年
      ?2月的闰年为29天,否则为28天
      ?1、3、5、7、8、10、12每个月的为31天
      ?4、6、9、11每个月为30天
      ?如果日期或月份为各位数,那么十位也可以加上0

      以上为我们分析的结果,那么根据我们的分析,我们先来构造自己的算法或者说方法。}

      年份:能被四整除的了,那么能被4整除的数字都什么特征呢?这是个数学问题了,如果你想不出来,可以再去翻一翻小学的数学书。这里我可以个告诉你以为十位 数为0、2、4、6、8个位为0、4、8以及十位是1、3、5、7、9各位是26可以被四整除。前两位是由0到9的两位数字组成[0-9]{2},后两位 闰年[02468][048]或者是[13579][26],完整闰年就是将这些都连起来([0-9]{2}([02468][048])|([13579][26]))那么非闰年呢?所有不能被4整除的就是,也就是把闰年的后两位反过来

      月份:接下来我们来从最特殊的入手,也就是2月,而其他的月份则与是否闰年无关先来看一下闰年的2月;2月的写法可以使2也可以是02,在正则里应该是[0]{0,1}[2]或者你也可以(2|02);还有大月(([0]{0,1}(1|3|5|7|8))|(10|12)、小月(([0]{0,1}(4|6))|11)

      日期:2月闰年是1到29天,非闰年是1到28天,从正则来考虑,十位是0到2,各位是0到8或0到9组成,闰年:([0][1-9])|([1-2][0-9],非闰年([0][1-9])|([1][0-9])|([2][0-8]),大月([0][1-9])|([1-2][0-9])|30|31小月([0][1-9])|([1-2][0-9])|30

     至此,我们的零部件已经制作完成,接下就是我们的组装过程,完整日期的合法性是怎么样子的呢?
     闰年-2月-闰2月的的日期
     或者
     非闰年-2月-非闰2月的的日期
     或者
     年份-大月-大月日期
     或者
     年份-小月-小月日期

润2月完整日期:(([0-9]{2}([02468][048])|([13579][26])))(-)(2|02)(-)(([0][1-9])|([1-2][0-9]))
非润2月完整日期:(([0-9]{2}([02468][123579])|([13579][01345789])))(-)(2|02)(-)(([0][1-9])|([1][0-9])([2][0-8]))
大月完整日期:([0-9]{4})(-)((([0]{0,1}(1|3|5|7|8))|(10|12))(-)(([0][1-9])|([1-2][0-9])|30|31)
小月完整日期:([0-9]{4})(-)((([0]{0,1}(4|6))|11))(-)(([0][1-9])|([1-2][0-9])|30)

     到这里我们的日期校验函数基本算是完工了,唯一要做的就是收尾工作了,把四个完整日期正则用|(或者)连起来,并且把它写到我们为String新增的函数中就算完工了:
   String.prototype.IsDate=function(){
    var
regexp = /^((([0-9]{2}([02468][048])|([13579][26])))(-)(2|02)(-)(([0][1-9])|([1-2][0-9])))|((([0-9]{2}([02468][123579])|([13579][01345789])))(-)(2|02)(-)(([0][1-9])|([1][0-9])([2][0-8])))|(([0-9]{4})(-)((([0]{0,1}(1|3|5|7|8))|(10|12))(-)(([0][1-9])|([1-2][0-9])|30|31))|(([0-9]{4})(-)((([0]{0,1}(4|6))|11))(-)(([0][1-9])|([1-2][0-9])|30))$/g;
    return
regexp.test(this);
  } 
    从现在开始我们就是这样来判断一个字符串是否为一个合法的日期了:
     var strDate ="2005-2-29"
     if(strDate.IsDate())
       
alert("这是一个正确的日期格式");
     else
       
alert("日期格式错误");

Posted on November 25, 2006 11:51 AM | | Comments (0) | TrackBacks (0)

<html>
<head>
<title>二级别下拉列表</title>
<script language="JavaScript">
<!--
/*
// +----------------------------------------------------------------------+
// | 无限级下拉列表 Version:dOption 0.1                                  |
// +----------------------------------------------------------------------+
// | Authors:   Moocky Mark                                                    |
*/
function c(s,i){this.s=s;this.i=i;}
function p(value,text){this.value=value;this.text=text;}
var where = new Array(4);
where[0]= new c(new p("wenxue","心情文学"),
        new Array(new p("topic","标题"),
             new p("user","作者"),
             new p("all","全文")));
where[1]= new c(new p("enjoy","文学鉴赏"),
        new Array(new p("topic","标题"),
             new p("litterateur","文人"),
             new p("all","全文")));
where[2]= new c(new p("forum","文学论坛"),
        new Array(new p("topic","标题"),
             new p("user","作者"),
             new p("all","全文")));
where[3]= new c(new p("news","站内新闻"),
        new Array(new p("topic","标题"),
             new p("all","全文")));
function loadSelect(){
 with(document.getElementById("sel1")){
  length = where.length;
  for(var i=0;i< where.length;i++){
   var p=where[i].s;
   options[i].value = p.value;
   options[i].text  = p.text;
  }
  onchange=Function("chgSelect();");
 }
 chgSelect();
}

function chgSelect(){
 with(document.getElementById("sel1")){
  for(var i=0; i < where.length ; i++){
   if(options[selectedIndex].value==where[i].s.value)
    var p = where[i].i;
  }
 }
 
 with(document.getElementById("sel2")){
  length = p.length;
  for(i=0;i < p.length;i++){
   options[i].value = p[i].value;
   options[i].text  = p[i].text;
  }
 }
}
//-->
</script>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="search" method="post" action="" target="_blank">
  <tr>
    <td width="42%" align="right" height="40">关键词:</td>
    <td width="58%" height="40"><input type="text" name="keyword" class="input" style="width:80px;"></td>
  </tr>
  <tr>
    <td width="42%" align="right" height="40">栏 目:</td>
    <td width="58%" height="40"><select id="sel1" name="d"></select></td>
  </tr>
  <tr>
    <td width="42%" align="right" height="40">字 段:</td>
    <td width="58%" height="40"><select id="sel2" name="type"></select>
    </td>
  </tr>
  <tr align="center">
    <td colspan="2" height="40"><input type="submit" name="Submit" value="搜  索"></td>
  </tr>
</form>
</table>
<script language="javascript">
loadSelect();
</script>
</body>
</html>

Posted on November 25, 2006 11:51 AM | | Comments (0) | TrackBacks (0)

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
 print_r($_POST);
}
?>

<html>
<head>
<title>n级别下来列表</title>
<script language="javascript" src="doptions.js"></script>
<script language="javascript">
<!--
/*
// +----------------------------------------------------------------------+
// | 无限级下拉列表 Version:dOption 0.1                                  |
// +----------------------------------------------------------------------+
// | Authors:   Moocky Mark                                                    |
// +----------------------------------------------------------------------+
// | LastUpdate:2006-07-19                                                  |
// +----------------------------------------------------------------------+
// | 请尊重作者的劳动成果,保留版权信息                                     |
// +----------------------------------------------------------------------+
*/
var d = new dOption('d');
d.add(1,0,'text_1_0_0_0_1','value_1_0_0_0_1');
d.add(2,1,'text_1_1_0_0_1','value_1_1_0_0_1');
d.add(3,1,'text_1_2_0_0_1','value_1_2_0_0_1');
d.add(4,1,'text_1_3_0_0_1','value_1_3_0_0_1');
d.add(5,2,'text_1_1_1_0_1','value_1_1_1_0_1');
d.add(6,2,'text_1_1_2_0_1','value_1_1_2_0_1');
d.add(7,2,'text_1_1_3_0_1','value_1_1_3_0_1');
d.add(8,6,'text_1_1_2_1_1','value_1_1_2_1_1');
d.add(9,6,'text_1_1_2_2_1','value_1_1_2_2_1');
d.add(10,6,'text_1_1_2_3_1','value_1_1_2_3_1');
d.add(11,0,'text_2_0_0_0_1','value_2_0_0_0_1');
d.add(12,11,'text_2_1_0_0_1','value_2_1_0_0_1');
d.add(13,11,'text_2_2_0_0_1','value_2_2_0_0_1');
d.add(14,11,'text_2_3_0_0_1','value_2_3_0_0_1');
d.add(15,12,'text_2_1_1_0_1','value_2_1_1_0_1');
d.add(16,12,'text_2_1_2_0_1','value_2_1_2_0_1');
d.add(17,12,'text_2_1_3_0_1','value_2_1_3_0_1');
d.add(18,16,'text_2_1_2_1_1','value_2_1_2_1_1');
d.add(19,16,'text_2_1_2_2_1','value_2_1_2_2_1');
d.add(20,16,'text_2_1_2_3_1','value_2_1_2_3_1');

function c(t){
 var nodes = d.nodes;
 var groups = d.groups;
 var inputName = parseInt(t.name.substring(t.name.indexOf('[')+1,t.name.indexOf(']')))+1;
 try{
  for(var i = inputName ; i < groups.length ; i++ ){
   //alert(i);
   d.delSelectElement(i);
  }
 }catch(e){
 }
 for(el in nodes){
  if(nodes[el].value==t.options[t.selectedIndex].value){
   var obj = null;
   /*判断selecet对象是否存在*/
   try{
    obj = document.getElementById(d.config.selectId+'_'+inputName).name;
   }catch(e){
   }
   if(groups[nodes[el].id]){
    if(obj==null)
     d.createSelectElement(inputName);
 
    d.parseDTree(nodes[el].id,inputName);
   }
  }
 }
}
//-->
</script>
</head>
<body>
<form action="" name="a" method="POST">
<p><span id="s"></span>
<script>
d.out();
</script>
</p>
<p>
<input type="submit" value="测试提交">
</form>
</body>
</html>

Posted on November 25, 2006 11:40 AM | | Comments (0) | TrackBacks (0)

具体步骤

方法一:用文本框的CSS属性ime-mode实现。

    <input onpaste="return false" ondragenter="return false"  style="ime-mode:disabled">

 提示:设置ime-mode为disabled的意思是禁止在输入时禁止用户激活输入中文,韩文,日文等的输入法(IME)状态,因为这个只能检测到键盘的输入,对通过鼠标操作的粘贴和拖放无效。

方法二:在松开按键时用脚本检查文本框的值,只保留Unicode编码在0和255之间的字符。

<script>
function check(str){
var temp=""
for(var i=0;i<str.length;i++)
     if(str.charCodeAt(i)>0&&str.charCodeAt(i)<255)
        temp+=str.charAt(i)
return temp
}
</script>
<input onpaste="return false" ondragenter="return false"  onkeyup="this.value=check(this.value)">


方法三:把所有双字节字符替换为空。

<input onpaste="return false" ondragenter="return false"  onkeyup="this.value=this.value.replace(/[^\x00-\x80]/gi,’’)">
    
方法四:把中文字符替换为空。

<input onpaste="return false" ondragenter="return false"  onkeyup="this.value=this.value.replace(/[\u0391-\uFFE5]/gi,’’)">

特别提示
本例代码运行后,第一种方法是不能切换输入法,所以无法输入中文,其它三种方法是在输入中文后立即被替换为空,同时禁止了粘贴和拖放事件。

特别说明



本例主要是css属性ime-mode和对中文或双字节字符的判断应用。
ime-mode 设置输入方法编辑器(IME)的状态。
charCodeAt返回指定位置上字符的 Unicode 编码值。

Posted on November 25, 2006 11:25 AM | | Comments (0) | TrackBacks (0)

功能说明:
滑动展开/收缩广告效果,可指定:广告完全展开时的停留时间,最大高度

兼容浏览器
IE5.0+、FF1.06+、Opera8.0+

实例代码

<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<title> 代码实例:滑动展开/收缩广告 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,CNLei.y.l@gmail.com">
<meta name="keywords" content="代码实例:滑动展开/收缩广告" />
<script type="text/javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
  this.stayTime=nStayTime*1000 || 3000;
  this.maxHeigth=nMaxHth || 90;
  this.minHeigth=nMinHth || 1;
  this.state=sState || "down" ;
  var obj = document.getElementById(id);
  if(intervalId != null)window.clearInterval(intervalId);
  function openBox(){
   var h = obj.offsetHeight;
   obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px";
    if(obj.offsetHeight>this.maxHeigth){
    window.clearInterval(intervalId);
    intervalId=window.setInterval(closeBox,this.stayTime);
    }
    if (obj.offsetHeight<this.minHeigth){
    window.clearInterval(intervalId);
    obj.style.display="none";
    }
  }
  function closeBox(){
   slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
  }
  intervalId = window.setInterval(openBox,10);
}
</script>
</head>
<body style="margin:0;padding:0;font-size:14px;">
<div id="MyMoveAd" style="background:#ff0;height:12px;overflow:hidden;">
<ul>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
 <li>这里是广告内内容</li>
</ul>
</div>
<p>代码实例:<strong>滑动展开/收缩广告</strong>&nbsp;&nbsp;&nbsp;请刷新页面,再次观看演示效果</p>
<script type="text/javascript">
 <!--
 slideAd('MyMoveAd',2);
-->
</script>
</body>
</html>

Continue reading "滑动展开/收缩广告代码实例效果"
Posted on November 23, 2006 7:13 PM | | Comments (0) | TrackBacks (0)

<script language="javascript">
function onSubmit() {
  var waitingInfo = document.getElementById(getNetuiTagName("waitingInfo"));
  waitingInfo.style.display = ""; //show the ProgressBar
  progress_update();    //begin the progressbar
  //waiting for several seconds,you would delete in your case
  for(i=0;i<1000000;i++){
   j=i+i;
  }
  location.href="progressbar.jsp"; //config your action page in here
 }


 // Build the netui_names table to map the tagId attributes
 // to the real id written into the HTML
 if (netui_names == null)
  var netui_names = new Object();
 netui_names.selectButton="portlet_15_1selectButton"
 // method which will return a real id for a tagId
 function getNetuiTagName(id) {
  return netui_names[id];
 }

 // method which will return a real id for a tagId,
 // the tag parameter will be used to find the scopeId for
 // containers that may scope their ids
 function getNetuiTagName(id, tag) {
  var scopeId = getScopeId(tag);
  if (scopeId == "")
     return netui_names[id];
  else
     return netui_names[scopeId  + "__" + id];
 }

 // method which get a tag will find any scopeId that,
 // was inserted by the containers
 function getScopeId(tag) {
    if (tag == null)
       return "";
    if (tag.getAttribute) { 
       if (tag.getAttribute('scopeId') != null)
          return tag.getAttribute('scopeId');
    } 
    if (tag.scopeId != null)
       return tag.scopeId;
    return getScopeId(tag.parentNode);
 }

 // Build the netui_names table to map the tagId attributes
 // to the real id written into the HTML
 if (netui_names == null)
    var netui_names = new Object();
 netui_names.waitingInfo="waitingInfo"

 var progressEnd = 15;  // set to number of progress <span>'s.
 var progressColor = 'green'; // set to progress bar color
 var progressInterval = 200; // set to time between updates (milli-seconds)

 var progressAt = progressEnd;
 var progressTimer;
 function progress_clear() {
  for (var i = 1; i <= progressEnd; i++)  
  document.getElementById('progress'+i).style.backgroundColor = 'transparent';
  progressAt = 0;
 }
 function progress_update() {
  progressAt++;
  if (progressAt > progressEnd) progress_clear();
  else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
  progressTimer = setTimeout('progress_update()',progressInterval);
 }
 function progress_stop() {
  clearTimeout(progressTimer);
  progress_clear();
 }
</script>



<span id="waitingInfo" style="display:none">
<table align="center"><tr><td>
正在处理数据, 请稍候......
<div style="font-size:2pt;padding:2px;border:solid black 1px">
<span id="progress1">   </span>
<span id="progress2">   </span>
<span id="progress3">   </span>
<span id="progress4">   </span>
<span id="progress5">   </span>
<span id="progress6">   </span>
<span id="progress7">   </span>
<span id="progress8">   </span>
<span id="progress9">   </span>
<span id="progress10">   </span>
<span id="progress11">   </span>
<span id="progress12">   </span>
<span id="progress13">   </span>
<span id="progress14">   </span>
<span id="progress15">   </span>
</div>
</td></tr></table>
</span>

<center>
点击按钮试试:
<input name="button" type="button" value="查询" onClick="javascript: return onSubmit();"> 
</center>

Posted on November 10, 2006 2:43 PM | | Comments (0) | TrackBacks (0)
Validator = {
 Require : /.+/,
 Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
 Phone : /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/,
 Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,
 Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
 IdCard : /^\d{18}(\d{2}[A-Za-z0-9])?$/,
 Currency : /^\d+(\.\d+)?$/,
 Number : /^\d+$/,
 Zip : /^[1-9]\d{5}$/,
 QQ : /^[1-9]\d{4,8}$/,
 Integer : /^[-\+]?\d+$/,
 Double : /^[-\+]?\d+(\.\d+)?$/,
 English : /^[A-Za-z]+$/,
 Chinese :  /^[\u0391-\uFFE5]+$/,
 UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
 IsSafe : function(str){return !this.UnSafe.test(str);},
 SafeString : "this.IsSafe(value)",
 Limit : "this.limit(value.length,getAttribute('min'),  getAttribute('max'))",
 LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
 Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
 Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
 Range : "getAttribute('min') < value && value < getAttribute('max')",
 Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
 Comparetonow : "this.comparetonow(value)",
 Compareto : "this.compareto(value,getAttribute('operator'),document.getElementsByName(getAttribute('to'))[0].value)",
 Custom : "this.Exec(value, getAttribute('regexp'))",
 Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
 ErrorItem : [document.forms[0]],
 ErrorMessage : ["以下原因导致提交失败:\t\t\t\t"],
 Validate : function(theForm, mode){
  var obj = theForm || event.srcElement;
  var count = obj.elements.length;
  this.ErrorMessage.length = 1;
  this.ErrorItem.length = 1;
  this.ErrorItem[0] = obj;
  for(var i=0;i<count;i++){
   with(obj.elements[i]){
    var _dataType = getAttribute("dataType");
    if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined")  continue;
    this.ClearState(obj.elements[i]);
    if(getAttribute("require") == "false" && value == "") continue;
    switch(_dataType){
     case "Date" :
     case "Repeat" :
     case "Range" :
     case "Compare" :
     case "Compareto":
     case "Comparetonow":
     case "Custom" :
     case "Group" :
     case "Limit" :
     case "LimitB" :
     case "SafeString" :
      if(!eval(this[_dataType])) {
       this.AddError(i, getAttribute("msg"));
      }
      break;
     default :
      if(!this[_dataType].test(value)){
       this.AddError(i, getAttribute("msg"));
      }
      break;
    }
   }
  }
  if(this.ErrorMessage.length > 1){
   mode = mode || 1;
   var errCount = this.ErrorItem.length;
   switch(mode){
   case 2 :
    for(var i=1;i<errCount;i++)
     this.ErrorItem[i].style.color = "red";
   case 1 :
    alert(this.ErrorMessage.join("\n"));
    this.ErrorItem[1].focus();
    break;
   case 3 :
    for(var i=1;i<errCount;i++){
    try{
     var span = document.createElement("SPAN");
     span.id = "__ErrorMessagePanel";
     span.style.color = "red";
     this.ErrorItem[i].parentNode.appendChild(span);
     span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");
     }
     catch(e){alert(e.description);}
    }
                                var fla = 0;
                                for(var i=1;i<errCount;i++){
      if(this.ErrorItem[i].getAttribute("type")!="hidden"){
                                  this.ErrorItem[i].focus();
                                             fla = 1;
                                                break;
      }
    }
                                if(fla==0) alert("请检查必添项!");
 
    break;
   default :
    alert(this.ErrorMessage.join("\n"));
    break;
   }
   return false;
  }
  return true;
 },
 limit : function(len,min, max){
  min = min || 0;
  max = max || Number.MAX_VALUE;
  return min <= len && len <= max;
 },
 LenB : function(str){
  return str.replace(/[^\x00-\xff]/g,"**").length;
 },
 ClearState : function(elem){
  with(elem){
   if(style.color == "red")
    style.color = "";
   var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
   if(lastNode.id == "__ErrorMessagePanel")
    parentNode.removeChild(lastNode);
  }
 },
 AddError : function(index, str){
  this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
  this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
 },
 Exec : function(op, reg){
  return new RegExp(reg,"g").test(op);
 },
 compare : function(op1,operator){
  var now=date();
  switch (operator) {
   case "NotEqual":
    return (op1 != now);
   case "GreaterThan":
    return (op1 > now);
   case "GreaterThanEqual":
    return (op1 >= now);
   case "LessThan":
    return (op1 < now);
   case "LessThanEqual":
    return (op1 <= now);
   default:
    return (op1 == now);
  }
 },
  compareto : function(op1,operator,op2){
  switch (operator) {
   case "NotEqual":
    return (op1 != op2);
   case "GreaterThan":
    return (op1 > op2);
   case "GreaterThanEqual":
    return (op1 >= op2);
   case "LessThan":
    return (op1 < op2);
   case "LessThanEqual":
    return (op1 <= op2);
   default:
    return (op1 == op2);
  }
 },
  comparetonow : function(op1){
  var now=(new java.util.Date()); 
    return (op1 > now);
 },
 MustChecked : function(name, min, max){
  var groups = document.getElementsByName(name);
  var hasChecked = 0;
  min = min || 1;
  max = max || groups.length;
  for(var i=groups.length-1;i>=0;i--)
   if(groups[i].checked) hasChecked++;
  return min <= hasChecked && hasChecked <= max;
 },
 IsDate : function(op, formatString){
  formatString = formatString || "ymd";
  var m, year, month, day;
  switch(formatString){
   case "ymd" :
    m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
    if(m == null ) return false;
    day = m[6];
    month = m[5]--;
    year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
    break;
   case "dmy" :
    m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
    if(m == null ) return false;
    day = m[1];
    month = m[3]--;
    year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
    break;
   default :
    break;
  }
  if(!parseInt(month)) return false;
  month = month==12 ?0:month;
  var date = new Date(year, month, day);
        return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
  function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
 }
 }
Posted on November 2, 2006 3:22 PM | | Comments (0) | TrackBacks (0)
上一页 1 2 3 4 5 6 7 8 下一页
相关内容
广告计划