是否可以通过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>
答案 0 :(得分:3)
您无法单独使用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>