【发布时间】:2021-06-02 20:20:50
【问题描述】:
您好,我正在使用我的 google 表格上的侧边栏来选择开始日期和结束日期点击按钮后选择的日期保持不变,这是我的 gs 代码
function StartDate(numstart){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName('DateFromTo').getRange('A2');
ws.setValue(numstart)
}
function EndDate(numend){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName('DateFromTo').getRange('B2');
ws.setValue(numend)
}
这是我的 html 代码的一部分,我尝试添加“return false”,但没有成功
<h4 class="text-left">From Date</h4>
<input type="date" class="form-control" id="startDate" name ="startDate" required>
<h4 class="text-left">To Date</h4>
<input type="date" class="form-control" id="endDate" name ="endDate" required>
</div>
<div class="form-group">
<button onclick="StartDate();EndDate(); return false;" type="button" class="btn btn-success col-md-2 btn-lg">Set Date</button>
</div>
<script>
function StartDate(){
var startdate = document.getElementById("startDate");
var numstart = startdate.value
google.script.run.StartDate(numstart);
document.getElementById("startDate").value=("")
}
</script>
<script>
function EndDate(){
var startdate = document.getElementById("endDate");
var numend = startdate.value
google.script.run.EndDate(numend);
document.getElementById("endDate").value=("")
}
</script>
谢谢
【问题讨论】:
-
很遗憾,我无法复制您在
what I'm having issue with is I would like for the selected date to remain and not be cleared after the button is clicked的情况。我为此道歉。我以为你的document.getElementById("startDate").value=("")和document.getElementById("endDate").value=("")可以用来清除它。那我能问一下你的情况吗? 1、你用的是什么浏览器? 2. 您能否提供一个示例电子表格来复制您的问题,包括您当前的脚本? -
您好 Tanaike 感谢您的回复,这是我为测试我的问题而创建的测试表的链接docs.google.com/spreadsheets/d/… 再次感谢
-
我用的是Chrome浏览器
-
感谢您回复并添加更多信息。根据您的回复,我提出了一个修改后的脚本作为答案。你能确认一下吗?
标签: javascript html google-apps-script google-sheets