• 问题:关于贴友一个用js传递value默认值的简单实现


    需求和代码如下:

    “这是我的代码:”

       1: <input type="text" id="price2" value="333"/>
       2: <input type="text" id="trueprice" value="" />
       3:
       4:
       5: <script type="text/javascript">
       6: document.getElementById("price2").onkeyup = function() {
       7: document.getElementById("trueprice").value = this.value;
       8: }
       9: </script>

    问题:现在打开这个页面,trueprice的值默认是空的,怎样才能实现默认打开这个页面trueprice就已经和price2一样了呢?(price2是一个动态的数值)
    <input type=”text” id=”trueprice” value=”” />是固定不可以修改的

     

    我的一个简单实现:

       1: <!DOCTYPE HTML>
       2: <html>
       3:     <head>
       4:         <meta http-equiv="content-type" content="text/html;charset=utf-8">
       5:         <title>Test</title>
       6:     </head>
       7:     <body>
       8:    <input type="text" id="price2" value="333"  onkeyup="test(this.value);"/>
       9:    <input type="text" id="trueprice" value="" />
      10:     <script type="text/javascript">
      11:         var price2 = document.getElementById("price2").value;
      12:         document.getElementById("trueprice").value = price2;
      13:         function test (defaultVal) {
      14:           document.getElementById("trueprice").value = defaultVal;
      15:         }
      16:     </script>
      17:
      18:     </body>
      19: </html>

    效果:


    在第一个文本框中输入的内容能同步到第二个文本框

     

    若你有不同意见,欢迎交流。不足之处,敬请谅解。

    来源:http://www.ido321.com/567.html

    关于js中设置默认参数,可以戳此:http://www.ido321.com/555.html


     

  • 相关阅读:
    linux软件安装
    [vim]使用中问题
    [vim]常用命令
    server
    linear regression
    loss function
    new bird in github
    [bzoj3489]A simple rmq problem
    [Jsoi2015]字符串树
    luogu3899谈笑风生
  • 原文地址:https://www.cnblogs.com/ido321/p/3966364.html
Copyright © 2020-2023  润新知