日期:2014-05-16  浏览次数:20370 次

本人JS菜鸟,向高手请教如何修改表单内容
在一个表格内,点击修改,会出现一个文本框,文本框的有原先的东西,修改文本框里的东西

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>    
        <style>
            * {
                margin:0; padding:0; font-size:14px;
            }
            table {
                margin:100px;
            }
            td {
                width:200px; height:30px; line-height:30px;
                border:1px solid blue;
            }
            input {
                width:200px; height:30px; line-height:30px;
                border:0;
            }
        </style>        
    </head>
    <body>
        <table>
            <tr>
                <td><input value="1-1" /></td>
                <td><input value="1-2" /></td>
            </tr>
            <tr>
                <td><input value="2-1" /></td>
                <td><input value="2-2" /></td>
            </tr>            
        </table>
        <script>
            function $(el){
                return typeof el == 'string' ? document.getElementById(el) : el;
            }
            function $t(name, cot){
                cot = cot || document;
                return cot.getElementsByTagName(name);
            }
            var arr = $t('input');
            for(var i = 0, len = arr.length; i < len; i++){
                arr[i].onfocus = function(){
                    this.style.border = '1px solid red';
                    this.parentNode.style.border = '0';
                }
                arr[i].onblur = function(){
                    this.style.border = 'none';
                    this.parentNode.style.border = '1px solid blue';
                }                
            }
        </script>
    </body>
</html>