我想访问表单和div中的输入元素。 我是Google应用程序脚本的新手,我认为我需要将包含DOM地址的参数从JS函数传递给应用程序脚本函数。
代码如下:
Javascript:
<script>
function update()
{
google.script.run.selectCell(document.getElementById(location));
alert("Success");//test message
}
</script>
HTML代码:
<div class="container">
<form>
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
Google App脚本:
function selectCell(domAddress)
{
var val0 = domAddress.value;
if (cell)
{
sheet.appendRow([val0]);
}
}
答案 0 :(得分:0)
ClientSide:
<div class="container">
<form id ="myForm">
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
</form>
<script>
function update()
{
google.script.run.selectCell(document.getElementById('myForm'));
alert("Success");//test message
}
</script>
服务器端:
function selectCell(formObject)
{
var val0 = formObject['location_txt']
if (val0)
{
sheet.appendRow([val0]);
}
}