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

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条)

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名