[英]Auto check the checkbox on meeting certain condition
如果滿足Google電子表格中的特定條件,是否可以自動檢查html中存在的復選框。
我有一個與單元格匹配的JavaScript,如果其值為1或任何定義的條件,則應自動選中“ name1”復選框。
這是我的名為code.gs的文件:
function openInputDialog() {
var html = HtmlService.createHtmlOutputFromFile('Index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Add Item');
}
function itemAdd(form) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var match1 = sheet.getRange("B2").getValue();
if(match1 === "1")
{
autocheck the checkbox "name1"; //cant figure out what to use here
}
Logger.log(form);
}
我的Index.html文件如下所示:-
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<form id='myForm'>
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td></td>
<td><input type="checkbox" name="name1" id="name1" value="1"/>xyz</td>
<td><input type="checkbox" name="name2" id="name2"/>abc</td>
<td><input type="checkbox" name="name3" id="name3"/>qwe</td>
<td><input type="checkbox" name="name4" id="name4"/>zxc</td>
</tr>
</tbody>
</table>
<br><br>
<input type="button" value="Submit" onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
</html>
您不能僅通過code.gs選中該復選框。 請參考下面的代碼。
code.gs
function getValues(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var match1 = sheet.getRange("B2").getValue();
return match1;
}
index.html ---在html頁面中添加以下腳本
<script>
google.script.run.withSuccessHandler(checkDefault).getValues();
function checkDefault(val){
var checkBoxName = "name"+val;
document.getElementById(checkBoxName).checked = true;
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.