cswsg123 2015-10-21 21:25 采纳率: 50%
浏览 5555
已采纳

html 如何在一个框中输入内容,然后点击按钮将此框中的内容复制到另一个框中

如题所说。 我想在 "group1currency1" 里输入一个数据 比如USD,然后点击下面的按钮,将"group1currency1"里的内容复制到”outputcurrency1“。 下面是我的代码,我尝试了很多次都不成功, 希望有人能帮助我

 <!DOCTYPE html>
<html>
<head> 
</head>
<body>
<p> Exchange Rates</P>
<table border="1">
<tr>
<th> </th>
    <th>Currency #1</th>
    <th>Currency #2</th>
    <th>Bid</th>
    <th>Ask</th>
    </tr>
    <tr>
    <td><p>Group 1</td>
   <td><input type="text" id="group1currency1"size="12" value=""></td>
    </tr>
    <tr>
    <td><p>Group 1</td>
   <td><input type="text" id="group2currency1"size="12" value=""></td>
    </tr>
    <tr>
    <td><p>Group 3</td>
   <td><span id="outputcurrency1"></td>
    </tr>
    </table>
    <button type="button" id="outputbutton" class="btn btn-success">Output</button>
 </div>
       <!-- jQuery -->
   <script src="js/exchange.js"></script>
   </script>
</body>
</html>

这个是我在js文档里的代码
var x= function(){
$("outputbutton").click(function(){
var str=document.getElementById("group1currency1").value;
document.getElementById("outputcurrency1").value = str;
});
};
  • 写回答

3条回答 默认 最新

  • Go 旅城通票 2015-10-22 02:08
    关注

    id选择器也搞错了。。span标签也没有闭合,乱用属性。。申明的方法也没有执行绑定事件

    jquery框架也未导入

     <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
        <p> Exchange Rates</p>
        <table border="1">
            <tr>
                <th> </th>
                <th>Currency #1</th>
                <th>Currency #2</th>
                <th>Bid</th>
                <th>Ask</th>
            </tr>
            <tr>
                <td><p>Group 1</td>
                <td><input type="text" id="group1currency1" size="12" value=""></td>
            </tr>
            <tr>
                <td><p>Group 1</td>
                <td><input type="text" id="group2currency1" size="12" value=""></td>
            </tr>
            <tr>
                <td><p>Group 3</td>
                <td><span id="outputcurrency1"></span></td>
            </tr>
        </table>
        <button type="button" id="outputbutton" class="btn btn-success">Output</button>
        </div>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
        <script >
    
            var x = function () {
                $("#outputbutton").click(function () {/////////
                    var str = document.getElementById("group1currency1").value;
                    document.getElementById("outputcurrency1").innerHTML = str;///////////
                });
            };
            x()///////////
        </script>
    
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能