gpt4 book ai didi

javascript - 如何将文本框值从一页传递到另一页?

转载 作者:行者123 更新时间:2023-11-28 04:32:26 25 4
gpt4 key购买 nike

我有 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>

代码.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.html的输出和output.html是相同的,它们有文本框,另一个有一个按钮。这段代码正在运行,我唯一的问题是如何通过 textbox value来自index.htmltextbox valuedisplay.html

这就是index.html看起来像

enter image description here

这就是 display.html看起来像

enter image description here

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

最佳答案

本地存储

保存变量

localStorage.setItem('NameOfLocalStorage',Value);

获取值

localStorage.getItem('NameOfLocalStorage');

关于javascript - 如何将文本框值从一页传递到另一页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com