JavaScript的动态表单

  1. <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>   
  2. <%   
  3. String path = request.getContextPath();   
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
  5. %>   
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
  8. <html>      
  9.     <meta http-equiv="pragma" content="no-cache">   
  10.     <meta http-equiv="cache-control" content="no-cache">   
  11.     <meta http-equiv="expires" content="0">       
  12.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">   
  13.     <meta http-equiv="description" content="This is my page">   
  14.         <!-- 淡入淡出的样式 -->   
  15.         <style  type="text/css">   
  16.             <!--    
  17.             .trans_msg   
  18.                 {   
  19.                 filter:alpha(opacity=100,enabled=1) revealTrans(duration=.2,transition=1) blendtrans(duration=.2);   
  20.                 }   
  21.             -->   
  22.         </style>   
  23.     <script type="text/javascript">   
  24.         //--初始化变量--   
  25.         var rT=true;//允许图像过渡   
  26.         var bT=true;//允许图像淡入淡出   
  27.            
  28.         var endaction=false;//结束动画   
  29.            
  30.         var ns4 = document.layers;   
  31.         var ns6 = document.getElementById && !document.all;   
  32.         var ie4 = document.all;   
  33.            
  34.         var toolTipSTYLE="";   
  35.         function initToolTips()   
  36.         {   
  37.           if(ns4||ns6||ie4)   
  38.           {   
  39.             if(ns4) toolTipSTYLE = document.toolTipLayer;   
  40.             else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;   
  41.             else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;   
  42.             if(ns4) document.captureEvents(Event.MOUSEMOVE);   
  43.             else  
  44.             {   
  45.               toolTipSTYLE.visibility = "visible";   
  46.               toolTipSTYLE.display = "none";   
  47.             }   
  48.           }   
  49.         }   
  50.         function toolTip(name)   
  51.         {   
  52.           if(toolTip.arguments.length < 1// hide   
  53.           {   
  54.                
  55.             if(ns4)    
  56.             {   
  57.             toolTipSTYLE.visibility = "hidden";   
  58.             document.form1.error.value="0";   
  59.             }   
  60.             else    
  61.             {   
  62.                  
  63.               //--图象过渡,淡出处理--   
  64.               if (!endaction) {toolTipSTYLE.display = "none";}   
  65.               if (rT) document.all("msg1").filters[1].Apply();   
  66.               if (bT) document.all("msg1").filters[2].Apply();   
  67.               document.all("msg1").filters[0].opacity=0;   
  68.               if (rT) document.all("msg1").filters[1].Play();   
  69.               if (bT) document.all("msg1").filters[2].Play();   
  70.               if (rT){    
  71.               if (document.all("msg1").filters[1].status==1 || document.all("msg1").filters[1].status==0){     
  72.               toolTipSTYLE.display = "none";}   
  73.               }   
  74.               if (bT){   
  75.               if (document.all("msg1").filters[2].status==1 || document.all("msg1").filters[2].status==0){     
  76.               toolTipSTYLE.display = "none";}   
  77.               }   
  78.               if (!rT && !bT) toolTipSTYLE.display = "none";   
  79.               //----------------------   
  80.             }   
  81.           }   
  82.           else // show   
  83.           {   
  84.             var tw=120;//提示框宽度   
  85.             var x=document.all[name].offsetLeft;   
  86.             var y=document.all[name].offsetTop;   
  87.             //alert(x + "    " + y);   
  88.             offsetX = 110;   
  89.             offsetY = 55;   
  90.                
  91.             if(name=="tdname1"){   
  92.               offsetX=10;   
  93.               offsetY=-10;   
  94.             }   
  95.             if(name=="tdname2"){   
  96.               offsetX=10;   
  97.               offsetY=-10;   
  98.             }   
  99.             if(name=="tdname3"){   
  100.               offsetX=10;   
  101.               offsetY=-10;   
  102.             }   
  103.            
  104.             var msg=getMessage(name);   
  105.             var fg = "#777777";//getFontColor();   
  106.             var bg = "#eeeeee";//getBgColor();   
  107.             var content =   
  108.             '<table id="msg1" name="msg1" border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '" class="trans_msg"><td>' +   
  109.             '<table border="0" cellspacing="0" cellpadding="3" bgcolor="' + bg +    
  110.             '"><td width=' + tw + '><font face="Arial" color="' + fg +   
  111.             '" size="-2">' + msg +   
  112.             ' \;</font></td></table></td></table>';   
  113.                
  114.             if(ns4)   
  115.             {   
  116.               toolTipSTYLE.document.write(content);   
  117.               toolTipSTYLE.document.close();   
  118.               toolTipSTYLE.visibility = "visible";   
  119.                
  120.               toolTipSTYLE.left = x + offsetX;   
  121.               toolTipSTYLE.top = y + offsetY;   
  122.             }   
  123.             if(ns6)   
  124.             {   
  125.               document.getElementById("toolTipLayer").innerHTML = content;   
  126.               toolTipSTYLE.display='block'  
  127.                 
  128.               toolTipSTYLE.left = x + offsetX;   
  129.               toolTipSTYLE.top = y + offsetY;   
  130.             }   
  131.             if(ie4)   
  132.             {   
  133.               document.all("toolTipLayer").innerHTML=content;   
  134.               toolTipSTYLE.display='block';   
  135.                 
  136.               toolTipSTYLE.left = x + offsetX;   
  137.               toolTipSTYLE.top = y + offsetY;   
  138.               //--图象过渡,淡入处理--   
  139.               var cssopaction=document.all("msg1").filters[0].opacity;   
  140.               document.all("msg1").filters[0].opacity=0  
  141.               if (rT) document.all("msg1").filters[1].Apply();   
  142.               if (bT) document.all("msg1").filters[2].Apply();   
  143.               document.all("msg1").filters[0].opacity=cssopaction;   
  144.               if (rT) document.all("msg1").filters[1].Play();   
  145.               if (bT) document.all("msg1").filters[2].Play();   
  146.               //----------------------   
  147.             }   
  148.           }   
  149.         }   
  150.         function getMessage(tdname){   
  151.             var msg="";   
  152.             if(tdname=="tdname1" || tdname=="tdname2" || tdname=="tdname3")   
  153.                 msg="请填写用户名";   
  154.             return msg;   
  155.         }   
  156.        
  157.         function sub(obj) {   
  158.             var my_tab = document.all("budgetTbl");   
  159.             //alert(my_tab.rows.length);   
  160.             if(my_tab.rows.length == 3) {   
  161.                 alert("至少保留一行");   
  162.             } else {   
  163.                 deleteRow(budgetTbl,obj.parentElement.parentElement.rowIndex);   
  164.             }   
  165.         }   
  166.         function checkrow() {   
  167.             insertRow(budgetTbl,budgetModel,-1);   
  168.         }   
  169.         //对指定表格按模板表格的内容插入一行   
  170.         //opTbl:要增加行的表格对象   
  171.         //modelTbl:模板表格   
  172.         //index:要插入的位置,-1表示添加到最后位置   
  173.         function insertRow(opTbl,modelTbl,index)   
  174.         {   
  175.             var rowObj;   
  176.             var rowAlign;   
  177.             var cellHtml;   
  178.             var cellClass;   
  179.             var cellAlign;   
  180.             var cellNoWarp;   
  181.             var cellObj;   
  182.             var cellColspan;   
  183.             for(var i=0;modelTbl!=null && i<modelTbl.rows.length;i++)   
  184.             {   
  185.                 if(index!=null && index>=0)   
  186.                 {   
  187.                     rowObj=opTbl.insertRow(index);   
  188.                        
  189.                 }else  
  190.                 {   
  191.                     rowObj=opTbl.insertRow();   
  192.                 }   
  193.                 rowObj.className=modelTbl.rows[i].className;   
  194.                 rowObj.align=modelTbl.rows[i].align;   
  195.                 for(var j=0;modelTbl.rows[i].cells!=null && j<modelTbl.rows[i].cells.length;j++)   
  196.                 {              
  197.                     cellHtml=modelTbl.rows[i].cells[j].innerHTML;   
  198.                     cellClass=modelTbl.rows[i].cells[j].className;   
  199.                     cellAlign=modelTbl.rows[i].cells[j].align;   
  200.                     cellNoWarp=modelTbl.rows[i].cells[j].noWarp;   
  201.                     //加一个colspan,跨几列   
  202.                     cellColspan=modelTbl.rows[i].cells[j].colSpan;   
  203.                     //alert(cellAlign);   
  204.                     //alert(cellColspan);   
  205.                        
  206.                     cellObj=rowObj.insertCell();   
  207.                     cellObj.align=cellAlign;   
  208.                     cellObj.className=cellClass;   
  209.                     cellObj.noWarp=cellNoWarp;   
  210.                     cellObj.innerHTML=cellHtml;   
  211.                     cellObj.colSpan = cellColspan;   
  212.                 }          
  213.             }   
  214.         }   
  215.         //删除指定表格的一行   
  216.         //opTbl:要操作的表格对象   
  217.         //index:要删除的行位置,-1表示删最后一行   
  218.         function deleteRow(opTbl,index)   
  219.         {   
  220.             if(opTbl==null)return;   
  221.             if(index==-1)   
  222.             {   
  223.                 if(opTbl.rows.length>1){opTbl.deleteRow(opTbl.rows.length-1);}   
  224.             }   
  225.             else  
  226.             {   
  227.                 opTbl.deleteRow(index);   
  228.             }   
  229.         }   
  230.     </script>   
  231.   </head>   
  232.      
  233.   <body>   
  234.     <!-- 初始化步骤 -->   
  235.     <div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>   
  236.     <p>   
  237.       <script>initToolTips()</script>   
  238.     </p>   
  239.     <form action="" method="post" name="form1">   
  240.         <table id="budgetTbl" border="1">   
  241.             <tr>   
  242.                 <td><input type="button" name="btn" value="插入一行" οnclick="checkrow()"></td>   
  243.             </tr>   
  244.             <tr align="center">   
  245.                 <td>操作</td>   
  246.                 <td id="tdname1" colspan="2">名字1</td>   
  247.                 <td id="tdname2">名字2</td>   
  248.                 <td id="tdname3">名字3</td>   
  249.             </tr>   
  250.             <tr align="center">   
  251.                 <td><input type="button" name="btn" value="删除" οnclick="sub(this)"></td>   
  252.                 <td colspan="2"><input type="text" name="name1" οnfοcus="toolTip('tdname1')" οnblur="toolTip()"></td>   
  253.                 <td><input type="text" name="name2" οnfοcus="toolTip('tdname2')" οnblur="toolTip()"></td>   
  254.                 <td><input type="text" name="name3" οnfοcus="toolTip('tdname3')" οnblur="toolTip()"></td>   
  255.             </tr>   
  256.         </table>   
  257.     </form>   
  258.     <!-- 模板表格 -->   
  259.     <table style="position:absolute; display: none" id="budgetModel">   
  260.         <tr align="center">   
  261.             <td><input type="button" name="btn" value="删除" οnclick="sub(this)"></td>   
  262.             <td colspan="2"><input type="text" name="name1" οnfοcus="toolTip('tdname1')" οnblur="toolTip()"></td>   
  263.             <td><input type="text" name="name2" οnfοcus="toolTip('tdname2')" οnblur="toolTip()"></td>   
  264.             <td><input type="text" name="name3" οnfοcus="toolTip('tdname3')" οnblur="toolTip()"></td>   
  265.         </tr>   
  266.     </table>   
  267.   </body>   
  268. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值