jquery练习4 获取文本框输入

来源:互联网 发布:java 程序运行时间 编辑:程序博客网 时间:2024/06/05 01:51

原文,使用原生js

非常基础的练习

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>    <meta http-equiv="Content-Type" content="text/html charset=utf-8" />    <script src="http://code.jquery.com/jquery-1.8.3.js">    </script>    <script type="text/javascript">    $(document).ready(function(){    $("#btn1").click(function(){    var sheng =document.getElementsByName("sheng");    var shi=document.getElementsByName("shi");    alert("省:"+$("#sheng").val());    alert("市:"+$("#shi").val());    });    });    </script>    <style type="text/css">body{margin: 0 auto;text-align: center;}    .wrapper{    width:500px;    height:300px;    line-height: 30px;    margin: 0 auto;    text-align: center;    }    input,button{    margin-top: 50px ;    }    </style>    <title>    获得用户输入的参数    </title></head><body>    <div class="wrapper"><input type="text" id ="sheng" placeholder="请输入省名"><br/><input type="text" id="shi" placeholder="请输入市名"><br/><button type="button" id="btn1">确认</button>    </div></body></html>