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      }
  • 相关阅读:
    信令基本概念
    CMMI
    关于OpenDataSource, OpenRowSet
    冒泡排序
    使用Sqlldr向oracle导入数据
    PowerDesigner生成sql和反向工程生成ER图的问题
    2021.1.4 学习总结
    12天 —— 关于生活与目标的思考【2020.8.5~2020.8.17】
    大一暑假学习总结(七)【2020.7.28~2020.8.4】
    学习:用javascript增加、删除行(转)
  • 原文地址:https://www.cnblogs.com/weihanli/p/3594859.html
Copyright © 2011-2022 走看看