javascript 实现 select手动输入

  1. <!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN">   
  2.   <!--   saved   from   url=(0060)http://www.51javascript.net/free/Messages/demo/me11-demo.htm   -->   
  3.   <HTML><HEAD><TITLE>可编辑菜单</TITLE>   
  4.   <META   content="提供知识指南,相关参考资料,js   编辑器,即免费脚本"   name=description>   
  5.   <META   content=指南,参考资料,技术论坛,脚本   name=keywords>   
  6.   <META   content="text/html;   charset=gb2312"   http-equiv=Content-Type>   
  7.   <SCRIPT   language=JavaScript>   
  8.     
  9.     
  10.   <!--   Begin   
  11.   var   o   =   null;   
  12.   var   isNN   =   (navigator.appName.indexOf("Netscape")!=-1);   
  13.   function   beginEditing(menu)   {   
  14.   finish();   
  15.   if(menu[menu.selectedIndex].value   !=   "read-only")   {   
  16.   o   =   new   Object();   
  17.   o.editOption   =   menu[menu.selectedIndex];   
  18.   o.editOption.old   =   o.editOption.text;   
  19.   o.editOption.text   =   "_";   
  20.   menu.blur();   
  21.   window.focus();   
  22.   document.onkeypress   =   keyPressHandler;   
  23.   }   
  24.   function   keyPressHandler(e){   
  25.   var   option   =   o.editOption;   
  26.   var   keyCode   =   (isNN)   ?   e.which   :   event.keyCode;   
  27.   if(keyCode   ==   8   ||   keyCode   ==   37)   
  28.   option.text   =   option.text.substring(0,option.text.length-2)   +   "_";   
  29.   else   if   (keyCode   ==   13)   {   
  30.   finish();   
  31.   }   else   
  32.   option.text   =   option.text.substring(0,option.text.length-1)   +   String.fromCharCode(keyCode)   +   "_";   
  33.   status   =   keyCode;   
  34.   }   
  35.   function   finish()   {   
  36.   if(o   !=   null)   {   
  37.   option   =   o.editOption;   
  38.   if(option.text.length   >   1)   
  39.   option.text   =   option.text.substring(0,option.text.length-1);   
  40.   else   
  41.   option.text   =   option.old;   
  42.   document.onkeypress   =   null;   
  43.   o   =   null;   
  44.               }   
  45.         }   
  46.   }   
  47.   //     End   -->   
  48.   </SCRIPT>   
  49.     
  50.   <META   content="MSHTML   5.00.2614.3500"   name=GENERATOR></HEAD>   
  51. <BODY   bgColor=#ffffff   vLink=#0000ff>   
  52.   <DIV   align=center><BR><BR><BR><BASEFONT><FONT   face=Helvetica,Arial   size=+2><FONT     
  53.   color=#0000ff><B>可编辑</B></FONT></FONT><FONT   face=Helvetica,Arial   size=+2><FONT     
  54.   color=#0000ff><B>菜单</B></FONT></FONT><BR><!--   Demonstration   --></DIV>   
  55.   <CENTER>   
  56.   <FORM><SELECT   οnchange=beginEditing(this);   size=7>   <OPTION     
  57.       value=read-only>Select   an   option   to   edit   it.</OPTION>   <OPTION     
  58.       value=read-only>   ----------------------------          
  59.                        </OPTION>   <OPTION     
  60.       value=last>SurName</OPTION>   <OPTION   value=first>FirstName</OPTION>   <OPTION     
  61.       value=email>Email</OPTION>   <OPTION   value=add1>Address   1</OPTION>   <OPTION     
  62.       value=add2>Address   2</OPTION></SELECT>   </FORM></CENTER>   
  63.   <P>   
  64.   <P>   
  65.   <P><A   name=source></A>   
  66.   <CENTER><!--content_stop-->   
  67.   <P>   
  68.   <SCRIPT   language=JavaScript>   
  69.   <!--   Begin   
  70.   function   getCookieVal   (offset)   {   
  71.   var   endstr   =   document.cookie.indexOf(";",   offset);   
  72.   if   (endstr   ==   -1)   
  73.   endstr   =   document.cookie.length;   
  74.   return   unescape(document.cookie.substring(offset,   endstr));   
  75.   }   
  76.   function   GetCookie   (name)   {   
  77.   var   arg   =   name   +   "=";   
  78.   var   alen   =   arg.length;   
  79.   var   clen   =   document.cookie.length;   
  80.   var   i   =   0;   
  81.   while   (i   <   clen)   {   
  82.   var   j   =   i   +   alen;   
  83.   if   (document.cookie.substring(i,   j)   ==   arg)   
  84.   return   getCookieVal   (j);   
  85.   i   =   document.cookie.indexOf("   ",   i)   +   1;   
  86.   if   (i   ==   0)   
  87.   break;   
  88.   }   
  89.   return   null;   
  90.   }   
  91.   function   SetCookie   (name,   value)   {   
  92.   var   argv   =   SetCookie.arguments;   
  93.   var   argc   =   SetCookie.arguments.length;   
  94.   var   expires   =   (argc   >   2)   ?   argv[2]   :   null;   
  95.   var   path   =   "/";   //(argc   >   3)   ?   argv[3]   :   null;   
  96.   var   domain   =   (argc   >   4)   ?   argv[4]   :   null;   
  97.   var   secure   =   (argc   >   5)   ?   argv[5]   :   false;   
  98.   document.cookie   =   name   +   "="   +   escape   (value)   +   
  99.   ((expires   ==   null)   ?   ""   :   (";   expires="   +   
  100.   expires.toGMTString()))   +   
  101.   ((path   ==   null)   ?   ""   :   (";   path="   +   path))   +   
  102.   ((domain   ==   null)   ?   ""   :   (";   domain="   +   domain))   +   
  103.   ((secure   ==   true)   ?   ";   secure"   :   "");   
  104.   }   
  105.     
  106.   var   emailcookie   =   GetCookie('email_address');   
  107.   if   (emailcookie   ==   null)   {   
  108.   emailcookie   =   'your   email   here';   
  109.   }   
  110.     
  111.   function   chk(email,   formname)   
  112.   {   
  113.   invalid   =   "";   
  114.     
  115.   if   (!email)   
  116.   invalid   =   "No   email   address   found!     Try   reloading   the   page   then   use   the   'email   a   script'   feature   again.";   
  117.     
  118.   else   {   
  119.     
  120.   if   (   (email.indexOf("@")   ==   -1)   ||   (email.indexOf(".")   ==   -1)   )     
  121.   invalid   +=   "/n/nInvalid   email   address.     Your   email   address   is   missing   an   '@'   sign   and   a   '.'   in   the   domain   name   (like   '.com').     Please   check   your   address   then   submit   again.";   
  122.     
  123.   if   (email.indexOf("youremailhere")   >   -1)   
  124.   invalid   +=   "/n/nInvalid   email   address.     Make   sure   your   email   address   included   your   username,   the   '@'   sign,   and   the   domain   name   (like   '.com').";   
  125.     
  126.   if   (email.indexOf("//")   >   -1)     
  127.   invalid   +=   "/n/nEmail   address   contains   an   invalid   back-slash   (//)   character.     Remove   the   character   and   submit   again.";   
  128.     
  129.   if   (email.indexOf("/")   >   -1)     
  130.   invalid   +=   "/n/nEmail   address   contains   an   invalid   forward-slash   (/)   character.     Remove   the   character   and   submit   again.";   
  131.     
  132.   if   (email.indexOf("'")   >   -1)     
  133.   invalid   +=   "/n/nEmail   address   contains   an   invalid   apostrophe   (')   character.     Remove   the   character   and   submit   again.";   
  134.     
  135.   if   (email.indexOf("zaz.com.br")   >   -1)     
  136.   invalid   +=   "/n/nPlease   do   not   use   an   email   address   that   has   an   autoresponder   set   up   for   it.     Thanks.";   
  137.     
  138.   if   (email.indexOf("!")   >   -1)     
  139.   invalid   +=   "/n/nEmail   address   contains   an   invalid   exclamation   point   (!)   character.     Remove   the   character   or   correct   the   email   address   then   submit   again.";   
  140.     
  141.   if   (   (email.indexOf(",")   >   -1)   ||   (email.indexOf(";")   >   -1)   )   
  142.   invalid   +=   "/n/nPlease   only   enter   one   email   address   in   the   box   at   a   time.     Remove   the   extra   addresses   and   submit   again.";   
  143.     
  144.   if   (email.indexOf("?subject")   >   -1)     
  145.   invalid   +=   "/n/nPlease   do   not   add   '?subject=...'   to   your   email   address.     Scriptbot   will   send   you   the   script   with   a   pre-defined   subject   already.     Please   remove   the   '?subject=...'   from   your   email   address   and   submit   again.";   
  146.   }   
  147.     
  148.   if   (invalid   ==   "")   
  149.         {   
  150.         var   largeExpDate   =   new   Date();   
  151.         largeExpDate.setTime(largeExpDate.getTime()   +   (31   *   24   *   3600   *   1000));   
  152.         SetCookie('email_address',   email,   largeExpDate);   
  153.         if   (formname   ==   "scriptbot")   
  154.               {   
  155.               page   =   "http://javascript.internet.com/sent.html?"   +   email;   
  156.               window.open(page,   "AdWindow",   "width=650,height=200");   
  157.               }   
  158.         return   true;   
  159.   }   
  160.   else     
  161.         {     
  162.         alert("Oops,   something   is   wrong...."   +   invalid);   
  163.         return   false;   
  164.         }   
  165.   }   
  166.     
  167.   function   updateNewsletters()   {   
  168.   with   (document.forms["newslettersignup"])   {   
  169.   emailStr   =   email.value;   
  170.   var   emailPat=/^(.+)@(.+)$/;   
  171.   var   specialChars="//(//)<>@,;:///"//.//[//]";   //   remove       (   )   <   >   @   ,   ;   :   /   "   .   [   ]         */   
  172.   var   validChars="/[^//s"   +   specialChars   +   "/]";   
  173.   var   quotedUser="(/"[^/"]*/")";   
  174.   var   ipDomainPat=/^/[(/d{1,3})/.(/d{1,3})/.(/d{1,3})/.(/d{1,3})/]$/;   
  175.   var   atom=validChars   +   '+';   
  176.   var   word="("   +   atom   +   "|"   +   quotedUser   +   ")";   
  177.   var   userPat=new   RegExp("^"   +   word   +   "(//."   +   word   +   ")*$");   
  178.   var   domainPat=new   RegExp("^"   +   atom   +   "(//."   +   atom   +")*$");   
  179.   var   matchArray=emailStr.match(emailPat);   
  180.   if   (matchArray==null)   {   
  181.   alert("Email   address   seems   incorrect   (check   @   and   .'s)");   
  182.   return   false;;   
  183.   }   
  184.   var   user=matchArray[1];   
  185.   var   domain=matchArray[2];   
  186.   if   (user.match(userPat)==null)   {   
  187.   alert("The   username   doesn't   seem   to   be   valid.");   
  188.   return   false;   
  189.   }   
  190.   var   IPArray=domain.match(ipDomainPat);   
  191.   if   (IPArray!=null)   {   
  192.   for   (var   i=1;i<=4;i++)   {   
  193.   if   (IPArray[i]>255)   {   
  194.   alert("Destination   IP   address   is   invalid!");   
  195.   return   false;   
  196.               }   
  197.         }   
  198.   }   
  199.   var   domainArray=domain.match(domainPat);   
  200.   if   (domainArray==null)   {   
  201.   alert("The   domain   name   doesn't   seem   to   be   valid.");   
  202.   return   false;   
  203.   }   
  204.   var   atomPat=new   RegExp(atom,"g");   
  205.   var   domArr=domain.match(atomPat);   
  206.   var   len=domArr.length;   
  207.   if   (domArr[domArr.length-1].length<2   ||   domArr[domArr.length-1].length>3)   {   
  208.   alert("The   address   must   end   in   a   three-letter   domain,   or   two   letter   country.");   
  209.   return   false;   
  210.   }   
  211.   if   (len<2)   {   
  212.   var   errStr="This   address   is   missing   a   hostname!";   
  213.   alert(errStr);   
  214.   return   false;   
  215.   }   
  216.   List_Name.value   =   newsletter.options[newsletter.selectedIndex].value   
  217.   +   nltype.options[nltype.selectedIndex].value;   
  218.     
  219.         var   largeExpDate   =   new   Date();   
  220.         largeExpDate.setTime(largeExpDate.getTime()   +   (31   *   24   *   3600   *   1000));   
  221.         SetCookie('email_address',   emailStr,   largeExpDate);   
  222.     
  223.   return   true;   
  224.         }   
  225.   }   
  226.   //   End   -->   
  227.   </SCRIPT>   
  228.     
  229.   <CENTER></CENTER></CENTER>   
  230.   <SCRIPT   language=JavaScript>                                                                                                                                     </SCRIPT>   
  231.   </BASEFONT></BODY></HTML>   
  232.   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值