程序实现input1中输入的字符串出现在input2中,但是在input2中出现是以类似镜像的形式。
现在问题是在input2里面输出是正确的,但是输出的字符串确实一闪而过就没了。
代码:    <script type="text/javascript">
function rcopy()
{
var t = document.form1.input1.value;
document.getElementsByTagName("form")[0].elements["input2"].value = t.split("").reverse().join();
}
function reset(o) {
    o.form.reset();
}
</script>
<body>
<form name="form1">
<input name="input1" />
<input name="input2" readonly/>
<button onclick="rcopy()">镜子</button>
<button onclick="reset(this)">重置</button>
</form></body>

解决方案 »

  1.   


       <script type="text/javascript">
    function rcopy()
    {
        var t = document.form1.input1.value;
        document.form1.input2.value = t.split("").reverse().join("");
    }
    function reset(o) {
        o.form.reset();
    }
    </script>
    <body>
    <form name="form1">
        <input name="input1"/>
        <input name="input2" readonly/>
        <button onclick="rcopy()">镜子</button>
        <button onclick="reset(this)">重置</button>
    </form>
      

  2.   

     或者写到 <input name="input1" onkeyup="rcopy()"/> 更逼真
      

  3.   

    你用form,點擊按鈕,頁面會自動刷新。
      

  4.   

    <button onclick="rcopy();return false">
            镜子</button>
    這樣應該可以。
      

  5.   

    如果在 HTML 表单中使用 button 元素,不同的浏览器会提交不同的值。Internet Explorer 将提交 <button> 与 <button/> 之间的文本,而其他浏览器将提交 value 属性的内容。请在 HTML 表单中使用 input 元素来创建按钮。
    也就是说,这里的button导致了表单的提交,注意看下面的地址
    http://localhost/UI/test/csdn/20110714_20.html?input1=%E6%96%87%E5%AD%97&input2=
    是我点击button之后的效果,文件是http://localhost/UI/test/csdn/20110714_20.html。
    解决办法是把button改为<input type="button">