zoukankan      html  css  js  c++  java
  • js实现点击按钮传值

    js实现点击按钮传值

    • page1源码:

        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="UTF-8">
        <script>
        function newDoc() {
        window.location.assign("hellow.html")
        }
        function quzhi() {
        var text1 = document.getElementById("name").value; //取得文本框的值
        var text2 = document.getElementById("password").value;
        alert(text1);//网页提示框
        alert(text2);
        var myurl = "Test_01" + "?" + "pname=" + text1 + "&password=" + text2;
        window.location.assign(encodeURI(myurl))
        }
        function quzhi2() {
        var text1 = document.getElementById("name").value; //
        var text2 = document.getElementById("password").value;
        var myurl = "hellow.jsp" + "?" + "pname=" + text1 + "&password="+ text2;
        window.location.assign(encodeURI(myurl))
        }
        </script>
        </head>
        <body>
        <input type="text" id="name" value="joy">
        <input type="text" id="password" value="123456">
        <br />
        <br />
        <input type="button" value="加载新页面" onclick="newDoc()">
        <br />
        <br />
        <input type="button" value="取值" onclick="quzhi()">
        <br />
        <br />
        <input type="button" value="传值" onclick="quzhi2()">
        </body>
        </html>
      
    • page2源码:

        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="UTF-8">
        <title>Insert title here</title>
        </head>
        <body topmargin="100" leftmargin="300">
        hellow  world!
        </body>
        </html>
      
    • page3源码:

        <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
        <!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">
        <title>Insert title here</title>
        </head>
        <body topmargin="100" leftmargin="300">
        <% 	
        String strName=request.getParameter("pname");
        String strPassword=request.getParameter("password");
        %>
      
        欢迎您!<%=strName %><br/>
        您的密码是:<%=strPassword %>
        </body>
        </html>
      
    • servlet源码:

        package test;
      
        import java.io.IOException;
        import javax.servlet.ServletException;
        import javax.servlet.annotation.WebServlet;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
      
        /**
        * Servlet implementation class Test_01
        */
        @WebServlet("/Test_01")
        public class Test_01 extends HttpServlet {
        private static final long serialVersionUID = 1L;
       
         /**
          * @see HttpServlet#HttpServlet()
          */
         public Test_01() {
        super();
        // TODO Auto-generated constructor stub
        }
        	/**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse 	response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
      
      
        String strName=request.getParameter("pname");
        String strPassword=request.getParameter("password");
        
        System.out.println(strName);
        System.out.println(strPassword);
      
      
        }
      
        	/**
        	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
        	 */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
        }
      
        }
      
    • 运行后图片

  • 相关阅读:
    无序数组求第K大/第K小的数
    [洛谷][二分搜索]进击的奶牛
    [015]向下类型转换和向上类型转换
    [014]析构函数为虚函数的注意事项
    [013]函数重载--int*和void*的匹配优先级
    [012]链表笔记--在链表中插入一个节点
    [011]链表笔记--删除一个链表节点
    [002]链表笔记--编程实现一个单链表的创建/测长/打印
    [C++]对象的销毁机制
    [011]默认实参
  • 原文地址:https://www.cnblogs.com/renxiuxing/p/8904211.html
Copyright © 2011-2022 走看看