zoukankan      html  css  js  c++  java
  • javascript页面间传递参数

    1.通过URL传递参数

    传递参数页

     1      function setCity()
     2 
     3      {
     4 
     5          var str = document.getElementById("cityName");
     6 
     7          if (str.value == null || str.value == "") {
     8 
     9              alert('请输入到达城市!');
    10 
    11              return;
    12 
    13          }
    14 
    15          else{
    16 
    17               var url="5.html?cityName="+str.value;
    18 
    19               alert(url);
    20 
    21               var urlInfo=encodeURI(url);
    22 
    23               window.location=urlInfo;
    24 
    25          }
    26 
    27 }

    <div class="main1of2" >到达城市:<input type="text" id="cityName"  /></div>

    <input type="image" src="../images/TJ.png" onmousedown="setCity()" onclick="setCity()" style="border: 0px;"/>

    接受参数页面

     1    function load()
     2 
     3    {
     4 
     5      var urlinfo = window.location.href;                                               //获取url
     6 
     7      var str = urlinfo.split("?")[1].split("=")[1];                                      
     8 
     9      //拆分url得到“=”号后面的值(先用split("?")[1]得到?号以后的值,再用split("=")[1]得到等号后面的值,split从0开始计数)
    10 
    11     var name = decodeURI(str);
    12 
    13   //decodeURI解码
    14 
    15     var imgUrl="../images/" + name + ".png";
    16 
    17     document.getElementById("imgBanci").src=imgUrl;
    18 
    19      }

    <img id="imgBanci" />

    2.通过剪贴板传递参数

         传递参数页:

        

     1  function setCity()
     2 
     3      {
     4 
     5          var str = document.getElementById("cityName");
     6 
     7          if (str.value == null || str.value == "") {
     8 
     9              alert('请输入到达城市!');
    10 
    11              return;
    12 
    13          }
    14 
    15          else {
    16 
    17              clipboardData.clearData("Text");
    18 
    19                    //清空剪贴板中“Text“格式的所有内容
    20 
    21              clipboardData.setData("Text",str.value);
    22 
    23                    //设置剪贴板中“Text“格式的内容
    24 
    25              window.location = "5.html";
    26 
    27                    //页面跳转
    28 
    29          }

         接受参数页

     1      function load()
     2 
     3      {
     4 
     5          var str = clipboardData.getData("Text");
     6 
     7          //访问剪贴板中的“Text“格式的内容
     8 
     9          var imgUrl = "../images/" + str + ".png";
    10 
    11          //生成图片路径
    12 
    13          document.getElementById("imgBanci").src = imgUrl;
    14 
    15      }
  • 相关阅读:
    HDU 4278 Faulty Odometer 8进制转10进制
    hdu 4740 The Donkey of Gui Zhou bfs
    hdu 4739 Zhuge Liang's Mines 随机化
    hdu 4738 Caocao's Bridges tarjan
    Codeforces Gym 100187M M. Heaviside Function two pointer
    codeforces Gym 100187L L. Ministry of Truth 水题
    Codeforces Gym 100187K K. Perpetuum Mobile 构造
    codeforces Gym 100187J J. Deck Shuffling dfs
    codeforces Gym 100187H H. Mysterious Photos 水题
    windows服务名称不是单个单词的如何启动?
  • 原文地址:https://www.cnblogs.com/weihanli/p/3594859.html
Copyright © 2011-2022 走看看