本帖最后由 singnore 于 2012-02-22 21:24:34 编辑

解决方案 »

  1.   

    有改进的希望能回复到这里!本人头一次来csdn发帖,算是给大家的见面礼了!
      

  2.   

    <%
    'ASP+JS仿Excel录入数据,可自定义设置表格行列数,实现上下左右方向键、回车键向下,屏蔽回车键、屏蔽F5刷新、页面屏蔽退格键(输入框不屏蔽)。
    '本代码设计思想来源于网络,但网络上的代码不够完整、不够实用,本代码设计灵活、简单方便。
    '设计者:Singnore(http://5dsc.com),设计时间:2012年2月22日,欢迎转载,请保留此段。
    '有再次改进的欢迎给我发一份([email protected]
    Dim ROWS,COLS  '可自定义设置表格行列数
    ROWS=16 '行数
    COLS=8 '列数
    InputWidth=120 '输入框宽度
    ThLeftWidth=60 '行名宽度
    %><style>
    table.formdata {
     border: 1px solid #5F6F7E;
     border-collapse: collapse;
    }
    table.formdata th {
     border: 1px solid #5F6F7E;
     background-color: #E2E2E2;
     color: #000000;
     text-align: center;
     font-weight: normal;
     padding: 2px 4px;
     margin: 0;
    }
    .thleft {
     width: <%=thleftwidth%>px;
    }
    table.formdata td {
     margin: 0;
     padding: 0;
     border: 1px solid #a2a2a2;
    }
    table.formdata input {
     width: <%=InputWidth%>px;
     padding: 2px 4px 2px 4px;
     margin: 0;
     border: 2px solid #ffffff;
     text-align: center;
    }
    .formdata input:focus {
     border: 2px solid #000000;
    }
    </style>
    <script language="javascript" type="text/javascript">
    function hilite(obj) {
     obj.style.border = '2px solid #000000';
    }
    function delite(obj) {
     obj.style.border = '2px solid #ffffff';
    }
    </script>
    <script language="javascript" event="onkeydown" for="document">
    if ( event.keyCode == 13 | event.keyCode == 116)
    {
    // 将 F5 键 和 退格键 屏蔽
    event.keyCode = 0;
    event.returnValue = false
    }
    if ( event.keyCode == 8  )
    {
    // 将 Enter 键 设置为 向下 键
    event.keyCode = 40;
    }
    </script>
    <script type="text/javascript">//索引,全局变量
    var text_ind;
    function of(text_index){
    text_ind = text_index;
    }function okd(){
    var code_value = event.keyCode;
    var next_name;
    var flag = false;//判断按键是否为 方向键右:
    if(code_value==39){
    flag = true;
    next_name = "Cell_"+(text_ind+1);
    }//判断按键是否为 方向键左:
    if(code_value==37){
    flag = true;
    next_name = "Cell_"+(text_ind-1);
    }//判断按键是否为 方向键上:
    if(code_value==38){
    flag = true;
    next_name = "Cell_"+(text_ind-<%=COLS%>);
    }//判断按键是否为 方向键下:
    if(code_value==40 | code_value==13){
    flag = true;
    next_name = "Cell_"+(text_ind+<%=COLS%>);
    }
    if(flag){
    document.getElementById(next_name).focus(); 

    }
    </script>
    <form id="form1" name="form1" method="post" action="">
    <table class="formdata" id="ttemp">
      <tr>
         <th> </th>
      <%
      For i=1 to COLS
      response.write "<th>列"& i &"</th>"
      Next%>
      </tr>
    <%For i=1 to ROWS*COLS
    If i=1 then response.write "<tr><th class=""thleft"" scope=""ROWS"">"&i&"</th>"response.write "<td><input type=""text"" name="""" id=""Cell_"& i &""" "
    response.write "onFocus=""of("& i &");this.select();hilite(this);"" onblur=""delite(this);""  onKeyDown=""okd()""   /></td>"If i=COLS*ROWS then
    response.write "</tr>"
    else
    If i mod COLS = 0 then  response.write "</tr><tr><th scope=""ROWS"">"&(i/COLS)+1&"</th>"
    End If
     
    Next
    %> </table>
    <p><input type="submit" name="Submit" value="提交"></p></form>