繁体   English   中英

如何将文本框值从一个页面传递到另一个页面?

[英]How to Pass Textbox Value from One Page to another?

我有3个文件。

index.html code.gsdisplay.html

的index.html

<!DOCTYPE html>
<html>
<head>
<style>
    .my_text
            {
                font-family:    Tahoma;
                font-size:      13px;
                font-weight:    normal;
            }
</style>


<base target="_top">
<script>
   function displayMessage() {
        var searchTerm;
        searchTerm = document.getElementById('idSrchTerm').value;
        console.log('searchTerm: ' + searchTerm );
         google.script.run.withSuccessHandler(handleResults).processForm(searchTerm.replace("'","\'")); 
       } 


          function handleResults(results){      
         var length=results.length;
             var table = document.getElementById("output");
             var count = document.getElementById("count");

         for(var i=0;i<length;i++)
         {




         var item=results[i];
         item=item.split("|~|");

     count.innerHTML = "Total Records Found : " + length;
     table.innerHTML  +="</br><a href='"+item[1]+"' target='_blank'>"+item[0]+"</a></br>  <B>Owner: </B>" +item[3]+ "   </br><B>Last modified: </B>"+item[2]+ "  </br> <B>File Size: </B>"+item[4]+"</br>";



        }


       }
function clearBox(elementID)
{
    document.getElementById("output").innerHTML = "";
     document.getElementById("count").innerHTML = "";
}










</script>




<style>
table, th, td {
    border: 1px solid black;
}
</style>

</head>

<body>


 <div class="container">


    <p class = "my_text"><input type="text" id="idSrchTerm" name="search" class = "my_text" >
    <input type="button" value="Search Drive" name="submitButton" class = "my_text" onClick="clearBox(); displayMessage();" />
<?var url = getScriptUrl();?><a target="_blank" href='<?=url?>?page=display'><input type="button" value="Open In New Tab" name="submitButton" class = "my_text" onClick="clearBox(); displayMessage();" value='display.html'/></a>

</div> 

<div id = "count" class = "my_text">
</div>

<div id ="output" class = "my_text">
</div>

</body>
</html>

code.gs

  var scriptProperties = PropertiesService.getScriptProperties();


function doGet(e) {

   Logger.log( Utilities.jsonStringify(e) );
  if (!e.parameter.page) {
    return HtmlService.createTemplateFromFile('index').evaluate();
  }
  return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();
return HtmlService.createHtmlOutputFromFile('display');
}


function getScriptUrl() {
  var url = ScriptApp.getService().getUrl();
 return url;
}


function SearchFiles(searchTerm) {
  var searchFor ="fullText contains '" + searchTerm + "'"; //single quotes are needed around searchterm



 var userProperties = PropertiesService.getUserProperties();
 userProperties.setProperty('SQuery', searchTerm);


 var userProperties = PropertiesService.getUserProperties();
 var SQuery = userProperties.getProperty('SQuery');
 Logger.log(SQuery);




  var names = [];
  var files = DriveApp.searchFiles(searchFor); 
    var searchQ = searchTerm;
  while (files.hasNext()) {
    var file = files.next();
    var fileId = file.getId();// To get FileId of the file
    var lm = file.getLastUpdated();
    var OType = file.getOwner().getName();
    var fsize = file.getSize()
    var name = file.getName()+"|~|"+file.getUrl()+"|~|"+lm+"|~|"+OType+"|~|"+fsize+"|~|"+searchQ; // Im concatenating the filename with file id separated by |~|
    names.push(name); // adding to the array
    Logger.log(file.getUrl());
  }
  return names; // return results


}


// Process the form
function processForm(searchTerm) {
  var resultToReturn;
  Logger.log('processForm was called! ' + searchTerm);
  resultToReturn  = SearchFiles(searchTerm); 
  Logger.log('resultToReturn: ' + resultToReturn);
  return resultToReturn; // return the results
}

display.html

<!DOCTYPE html>
<html>
<head>
<style>
    .my_text
            {
                font-family:    Tahoma;
                font-size:      13px;
                font-weight:    normal;
            }
</style>


<base target="_top">
<script>
   function displayMessage() {
        var searchTerm;
        searchTerm = document.getElementById('idSrchTerm').value;
        console.log('searchTerm: ' + searchTerm );
         google.script.run.withSuccessHandler(handleResults).processForm(searchTerm.replace("'","\'")); 
       } 


          function handleResults(results){      
         var length=results.length;
             var table = document.getElementById("output");
             var count = document.getElementById("count");

         for(var i=0;i<length;i++)
         {




         var item=results[i];
         item=item.split("|~|");

     count.innerHTML = "Total Records Found : " + length;
     table.innerHTML  +="</br><a href='"+item[1]+"' target='_blank'>"+item[0]+"</a></br>  <B>Owner: </B>" +item[3]+ "   </br><B>Last modified: </B>"+item[2]+ "  </br> <B>File Size: </B>"+item[4]+"</br>";



        }


       }
function clearBox(elementID)
{
    document.getElementById("output").innerHTML = "";
     document.getElementById("count").innerHTML = "";
}










</script>




<style>
table, th, td {
    border: 1px solid black;
}
</style>

</head>

<body onload ="clearBox(); displayMessage();">


 <div class="container">


    <p class = "my_text">

    <input type="text" id="idSrchTerm" name="search" class = "my_text" value = "outing" >


</div> 

<div id = "count" class = "my_text">
</div>

<div id ="output" class = "my_text">
</div>

</body>
</html>

实际上index.htmloutput.html的输出与文本框相同,另一个有按钮。 这段代码工作我唯一的问题是如何将textbox valueindex.html传递到display.html textbox value

这就是index.html样子

在此输入图像描述

这就是display.html样子

在此输入图像描述

我唯一的目标是将文本框值从一个站点传递到另一个站点,然后从中我可以运行我的代码<body onload>这就是我需要从其他站点TYSM的另一个文本框中传递文本框值来寻求帮助

Ty本地存储

保存变量

localStorage.setItem('NameOfLocalStorage',Value);

获得价值

localStorage.getItem('NameOfLocalStorage');

您可以通过链接发送数据,例如:

window.location.href = "output.html?" + encodeURIComponent('blah blah bla')

你可以在output.html中检索数据

var data = decodeURIComponent(window.location.search.substr(1))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM