声明:本人是js菜鸟在同一个页面中,要实现将一个文本框(区域)中的一行值(假设共有3行)想转移到另一个文本框中。如何实现。
请高手指点江山。谢谢

解决方案 »

  1.   

    text2.value = text1.value 
      

  2.   

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <style type="text/css">
    textarea { height:300px; width:300px; }
    </style>
    <textarea name="t1" id="t1">
    第一行
    第二行
    第三行
    </textarea>
    <textarea name="t2" id="t2"></textarea>
    <input type="button" id="mvLine" onclick="mvLine(2)" value="点击移动左边第二行移动到右边" />
    <script type="text/javascript">
    function mvLine(line) {
    var arr = document.getElementById('t1').value.split('\n');
    if (arr[line-1]) {
    document.getElementById('t2').value = arr[line-1];
    arr[line-1] = '';
    var arrtmp = new Array();
    for(var i = 0; i < arr.length; i ++) {
    if (arr[i].length > 0) arrtmp.push(arr[i]);
    }
    document.getElementById('t1').value = arrtmp.join('\n');
    }
    }
    </script>
    </body>
    </html>