周圍有很多例子,但我找不到覆寫一張桌子的例子。如果在相鄰列中選擇了值 Rejected 或 Discuss,則目的是讓 Comments 列的輸入欄位顯示為必填欄位。
這是一個小提琴
我已經看到應該在表的每一行中添加一個 onchange,它會呼叫一個函式,但是每一行都應該有一個 id 嗎?
這就是我使用 GAS 構建表格的方式:
function createTable(dataArray) {
if (dataArray && dataArray !== undefined && dataArray.length != 0) {
var option = "<select name='D1'>"
"<option value='empty'></option>"
"<option value='Approved'>Approved</option>"
"<option value='Discuss'>Discuss</option>"
"<option value='Rejected'>Rejected</option>"
"</select>";
var textBox = "<input type='text' name='comments'/>"
var result = "<div class='card'><table class='table table-borderless table-hover' id='dtable'>"
"<thead style='white-space: nowrap'>"
"<tr>" //Change table headings to match witht he Google Sheet
"<th class='text-center'>Notes</th>"
"<th class='text-center'>Approval</th>"
"<th class='text-center'>Comments</th>"
"</tr>"
"</thead>"
"<tbody>";
for (var i = 0; i < dataArray.length; i ) {
result = "<tr>";
for (var j = 0; j < dataArray[i].length; j ) { //Checks if Link columns has data and pushes it as a link into the table
result = "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'>" dataArray[i][j] "</td>";
}
result = "<td class='align-middle' style='text-align:center'>" option "</td>";
result = "<td class='align-middle' style='text-align:center'>" textBox "</td>";
result = "</tr>";
}
result = "</tbody></table></div><br>";
var div = document.getElementById('search-results');
div.innerHTML = result;
} else {
var div = document.getElementById('search-results');
div.innerHTML = "Data not found!";
return;
}
}
感謝你的幫助!
uj5u.com熱心網友回復:
為 selectValueChanged 等選擇框添加 onChange 事件,然后在方法內部傳遞當前物件。使用當前物件,找到選定的值,然后執行您的操作。
function selectValueChanged(cur){
if(cur.value == "Rejected" || cur.value == "Discuss"){
cur.parentElement.nextElementSibling.children[0].required = true;
cur.parentElement.nextElementSibling.children[0].placeholder = "this is requred";
}else{
cur.parentElement.nextElementSibling.children[0].required = false;
cur.parentElement.nextElementSibling.children[0].placeholder = "Optional";
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/488100.html
上一篇:如何從電子郵件中提取數字
