用JS获取输入框中的值

lile2017    2018-8-23

<!DOCTYPE html>
<html>
        <head>
                <meta charset="utf-8">
                <title></title>
                <style>
                        .wrap{                                 
                                text-align: center;
                        }
                        .wrap input{
                                display: block;
                                margin: 10px auto;                                
                        }
                </style>
        </head>
        <body>
                <div class="wrap">
                        <input type="text" name="" id="shi" value="北京市" />
                        <input type="text" name="" id="qu" value="朝阳区" />
                        <input type="button" name="btn" id="btn" value="传参" />
                </div>
                <script>
                        var btn=document.getElementById("btn");
                        var shi=document.getElementById("shi");
                        var qu=document.getElementById("qu");
                        
                        btn.onclick=function(){
                                alert(shi.value);
                                alert(qu.value);
                        }
                </script>
        </body>
</html>





暗色背景
手机扫码阅读本页