我試著做一個側邊欄來輸入個人費用,但是提交按鈕不起作用。如果有人能看一下表單和AppScript,我將不勝感激。如果你覺得合適,可以隨意修改。謝謝!
我過去也問過類似的問題,但密碼不同。
https://docs . Google . com/spreadsheets/d/1g8k _ uy buc 9 hkmyd 9 odpczctp 3 fky 6 qxanpeqkvjpvq 4/edit # GID = 1349359857
有幾個問題:
1.HTML代碼中沒有名為displayReturn的元素。 這就是為什么按鈕不起作用,只在控制臺中顯示一個錯誤。基于原始源代碼,您可以在代碼末尾添加這個元素。
...
<div class="block">
</div>
<div class="block">
<strong>Footer</strong> Lorem ipsum.
</div>
<div id="displayReturn"></div>
</body>
2.有多個元素具有相同的id。 JavaScript將獲取具有所請求Id的第一個元素,因為它假設該元素是唯一的,使用當前實現,它將傳遞在您嘗試使用的元素之前編碼的元素,例如:
更改自:
<div class="field" id="description">
<label class="label">Description</label>
<div class="control">
<input class="input is-rounded" id="description" type="text" placeholder="Text input">
</div>
</div>
收件人:
<div class="field" for="description">
<label class="label">Description</label>
<div class="control">
<input class="input is-rounded" id="description" type="text" placeholder="Text input">
</div>
</div>
工作HTML正文:
<body>
<div class="tabs">
<ul>
<li class="tablinks is-active">
<a onclick="openTab(event, 'Home')">
<span>Home</span>
</a>
</li>
</ul>
</div>
<div class="container is-fluid">
<div class="tabcontent" id="Home">
<div class="field" for="date">
<label class="label">Date</label>
<div class="control">
<input class="input is-rounded" id="date" type="date" placeholder="Select a date">
</div>
</div>
<div class="field" for="description">
<label class="label">Description</label>
<div class="control">
<input class="input is-rounded" id="description" type="text" placeholder="Text input">
</div>
</div>
<div class="field" for="remarks">
<label class="label">Remarks (optional)</label>
<div class="control">
<input class="input is-rounded" id="remarks" type="text">
</div>
</div>
<div class="field" for="payment_method">
<label class="label">Payment method</label>
<div class="control">
<div class="select is-rounded">
<select id="payment_method">
<option></option>
<? var values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings").getRange("G12:G51").getValues().flat().filter(String); ?>
<? values.forEach(function(value) { ?>
<option value="<?= value ?>"><?= value ?></option>
<? }); ?>
</select>
</div>
</div>
</div>
<div class="field" for="amount">
<label class="label">Amount</label>
<div class="control">
<input class="input is-rounded" id="amount" type="number" step="0.01">
</div>
</div>
<div class="field" for="category">
<label class="label">Category</label>
<div class="control">
<div class="select is-rounded">
<select id="category">
<option></option>
<? var values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings").getRange("C12:C51").getValues().flat().filter(String); ?>
<? values.forEach(function(value) { ?>
<option value="<?= value ?>"><?= value ?></option>
<? }); ?>
</select>
</div>
</div>
</div>
<div class="field" for="subcategory">
<label class="label">Sub-category</label>
<div class="control">
<div class="select is-rounded">
<select id="subcategory">
<option></option>
<? var values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings").getRange("D12:D51").getValues().flat().filter(String); ?>
<? values.forEach(function(value) { ?>
<option value="<?= value ?>"><?= value ?></option>
<? }); ?>
</select>
</div>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link is-rounded" onclick="SubmitRecord()">Submit</button>
</div>
<div class="control">
<button class="button is-link is-light is-rounded">Cancel</button>
</div>
</div>
</div>
<div class="block">
</div>
<div class="block">
<strong>Footer</strong> Lorem ipsum.
</div>
<div id="displayReturn"></div>
</body>
參考:
getElementById()