兩個input,一個在其中一個輸入,內容在另一個input中實時回顯
代碼如下
<!DOCTYPE html> <html> <head> <title>demo.html</title> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div style='padding:100px;width:60%'> <div> <h3>一個input聯動的demo</h3> </div> <hr> <div> <div>id為master的input</div> <input id='master' type='text' class='form-control'> </div> <div> <div>id為slave的input</div> <input id='slave' type='text' class='form-control'> </div> </div> </body> <script type="text/javascript"> $(function() { $('#master').keyup(function() { //master鍵入過程中的監聽函數 var me = $(this); //獲取master的input var val = me.val(); //獲取master的input的val $('#slave').val(val); //將master中鍵入的內容實時的拿到slave中; }) }) </script> </html>
效果如下

