【发布时间】:2015-03-29 07:29:07
【问题描述】:
我有一个表格,如下所示:
HTML 和 JavaScript
<form>
<table border="1" id="tblSample">
<tr>
<th>Col_one</th>
<th>Col_two</th>
<th>Col_three</th>
</tr>
<tr>
<td><input type="text" name="txtRowa1"
id="txtRowa1" size="5" /></td>
<td>
<input type="text" name="txtRowb1"
id="txtRowb1" size="15" /> </td>
<td>
<input type="text" name="txtRowc1"
id="txtRowc1" size="15" /> </td>
</tr>
<tr>
<td><input type="text" name="txtRowa2"
id="txtRowa2" size="5" /></td>
<td>
<input type="text" name="txtRowb2"
id="txtRowb2" size="15" /> </td>
<td>
<input type="text" name="txtRowc2"
id="txtRowc2" size="15" /> </td>
</tr>
<tr>
<td><input type="text" name="txtRowa3"
id="txtRowa3" size="5" /></td>
<td>
<input type="text" name="txtRowb3"
id="txtRowb3" size="15" /> </td>
<td>
<input type="text" name="txtRowc3"
id="txtRowc3" size="15" /> </td>
</tr>
</table>
</form>
<p>
<input onclick="formSubmit()" type="button" value="Send data" />
</p>
<script type="text/javascript">
function formSubmit() {
google.script.run.getValuesFromForm(document.forms[0]);
}
</script>
这个表需要放到电子表格里,gs文件是:
//getValuesFromForm
function getValuesFromForm(form){
var tempa1 = form.txtRowa1,
tempb1 = form.txtRowb1,
tempc1 = form.txtRowc1,
tempa2 = form.txtRowa2,
tempb2 = form.txtRowb2,
tempc2 = form.txtRowc2,
tempa3 = form.txtRowa3,
tempb3 = form.txtRowb3,
tempc3 = form.txtRowc3,
sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.appendRow([tempa1, tempb1, tempc1]);
sheet.appendRow([tempb1, tempb2, tempc2]);
sheet.appendRow([tempc1, tempc2, tempc3]);
}
但问题是:表格是动态的,我不知道会有多少行(在这种情况下有 3 行)我如何从表格中获取值?
【问题讨论】:
-
您正在寻找类似:
document.getElementsByTagName('tr').length?
标签: javascript html google-apps-script google-sheets web-applications