开发者社区> 问答> 正文

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;
});
};

展开
收起
小旋风柴进 2016-03-20 09:37:24 3227 0
1 条回答
写回答
取消 提交回答
  • 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>
    2019-07-17 19:08:38
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
《零基础HTML入门教程》 立即下载
天猫 HTML5 互动技术实践 立即下载
天猫HTML5互动技术实践 立即下载