我试图让这个表显示每个表行的选项,但我不太明白:
我想我会把它设置在第二个for loop
,但我是新手html
并且无法前进。
<script>
//PREVENT FORMS FROM SUBMITTING / PREVENT DEFAULT BEHAVIOUR
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener("load", preventFormSubmit, true);
//HANDLE FORM SUBMISSION
function handleFormSubmit(formObject) {
google.script.run.withSuccessHandler(createTable).processForm(formObject);
//document.getElementById("search-form").reset();
}
//CREATE THE DATA TABLE
function createTable(dataArray) {
if(dataArray && dataArray !== undefined && dataArray.length != 0){
var result = "<table class='table table-sm table-striped' id='dtable' style='font-size:0.8em'>"+
"<thead style='white-space: nowrap'>"+
"<tr>"+ //Change table headings to match witht he Google Sheet
"<th scope='col'>Client</th>"+
"<th scope='col'>Name</th>"+
"<th scope='col'>Date</th>"+
"<th scope='col'>Approval</th>"+
"</tr>"+
"</thead>";
for(var i=0; i<dataArray.length; i++) {
result += "<tr>";
for(var j=0; j<dataArray[i].length; j++){
result += "<td>"+dataArray[i][j]+"</td>";
}
result += "</tr>";
}
result += "</table>";
var div = document.getElementById('search-results');
div.innerHTML = result;
}else{
var div = document.getElementById('search-results');
//div.empty()
div.innerHTML = "Data not found!";
}
}
</script>
这是该文件的 https://docs.google.com/spreadsheets/d/1BDTfDfVimE6X7hXFziKX5fgFzG3IiATvf3V6MBoAke8/edit?usp=sharing
这是网络应用程序 URL https://script.google.com/macros/s/AKfycbxNn4I2tZRXlDKrBcyp8S6EciMAdug3FvRFoIIjLHky5z74Qa0kdzkRFGfMeOjFODPV/exec
Here's the current result:
我相信您的目标如下。
既然如此,下面的修改如何?
修改后的脚本:
请修改函数createTable
如下。
function createTable(dataArray) {
if (dataArray && dataArray !== undefined && dataArray.length != 0) {
var option = "<select name='D1'>" +
"<option value='volvo'>Volvo</option>" +
"<option value='saab'>Saab</option>" +
"<option value='mercedes'>Mercedes</option>" +
"<option value='audi'>Audi</option>" +
"</select>";
var result = "<table class='table table-sm table-striped' id='dtable' style='font-size:0.8em'>" +
"<thead style='white-space: nowrap'>" +
"<tr>" + //Change table headings to match witht he Google Sheet
"<th scope='col'>Client</th>" +
"<th scope='col'>Name</th>" +
"<th scope='col'>Date</th>" +
"<th scope='col'>Approval</th>" +
"<td>" +
"</td>" +
"</tr>" +
"</thead>";
for (var i = 0; i < dataArray.length; i++) {
result += "<tr>";
for (var j = 0; j < dataArray[i].length; j++) {
result += "<td>" + dataArray[i][j] + "</td>";
}
result += "<td>" + option + "</td>";
result += "</tr>";
}
result += "</table>";
var div = document.getElementById('search-results');
div.innerHTML = result;
} else {
var div = document.getElementById('search-results');
//div.empty()
div.innerHTML = "Data not found!";
}
}
-
option
来自你之前的问题。Ref https://stackoverflow.com/q/72252525/7108653
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)