問題:關於貼友一個用js傳遞value預設值的簡單實現

來源:互聯網
上載者:User

標籤:js

需求和代碼如下:

“這是My Code:”

   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



問題:關於貼友一個用js傳遞value預設值的簡單實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.