Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加<;选择>;内部<;td>;_Javascript_Html_Google Apps Script - Fatal编程技术网

Javascript 添加<;选择>;内部<;td>;

Javascript 添加<;选择>;内部<;td>;,javascript,html,google-apps-script,Javascript,Html,Google Apps Script,我有一段代码,它创建了一个包含7列的表 该表返回如下所示: [1] [2][3][4][5][6][7]只需确定您要将其放置在何处,并为下面的函数指定您的选项CSV字符串和值SCSV字符串,它将为选择和选项打开和关闭标记生成所有标记 function mySelect(optionscsv,valuescsv) { var optionscsv = (typeof(optionscsv) !== 'undefined')?optionscsv : null; var valuescsv

我有一段代码,它创建了一个包含7列的表

该表返回如下所示:

[1] [2][3][4][5][6][7]只需确定您要将其放置在何处,并为下面的函数指定您的选项CSV字符串和值SCSV字符串,它将为选择和选项打开和关闭标记生成所有标记

function mySelect(optionscsv,valuescsv)
{
  var optionscsv = (typeof(optionscsv) !== 'undefined')?optionscsv : null;
  var valuescsv = (typeof(valuescsv) !== 'undefined')?valuescsv : null;
  var s='<select>';
  if(valuescsv && optionscsv)
  {
    var optionsA = optionscsv.split(',');
    var valuesA = valuescsv.split(',');
    if(optionsA.length == valuesA.length)
    {
      for(var i = 0; i < optionsA.length; i++)
      {
        s += '<option value="' + valuesA[i] + '">' + optionsA[i] + '</option>';
      }
      s += '</select>';
    }
    else
    {
      s ='';
    }

  }
  else
  {
    s = '';
  }
  return s;
}
函数mySelect(选项CSV、值SCSV)
{
var optionscsv=(typeof(optionscsv)!=‘未定义’?optionscsv:null;
var valuescsv=(类型(valuescsv)!=‘未定义’?valuescsv:null;
var s='';
如果(值csv&&options csv)
{
var optionsA=optionscv.split(',');
var valuesA=价值分类(',');
如果(选项A.length==值A.length)
{
对于(变量i=0;i
下面我猜了一下你可能想把它放在哪里,以及你怎么做。但我可能错了,所以如果需要,请回来寻求更多帮助

for (var j = 0; j < artistFileValues[i].length; j++)
    {
      if (isHeader)
      {
        table += "<th>" + artistFileValues[i][j] + "</th>\n"; //headers
        if (j == artistFileValues[i].length - 1) //if last header in row, add another cell with 'add' button
        {
          table += "<th style='text-align: center;'>" + "<a id='addButton' onclick=\x22addRow(this)\x22>" + "&plus;" + "</a>" + "</th>\n"; //'+' button
        }
      }
      else
      {
        if(j!==5)//I'm guessing this is the sixth column
        {
            table += "<td contenteditable='false'>" + artistFileValues[i][j] + "</td>\n"; //values
        }
        else
        {
            var s = mySelect(optionscsv,valuescsv);
            table += "<td contenteditable='false'>" + artistFileValues[i][j] + s + "</td>\n"; //values
        }
        if (j == artistFileValues[i].length - 1) //if last data in row, add another cell with 'delete' button
        {
          table += "<td style='text-align: center;'>" + "<a id='deleteButton' onclick=\x22deleteRow(this)\x22>" + "&times;" + "</a>" + "</td>\n"; //'x' button
        }
      }
    }
for(var j=0;j
要进入主题,请首先向我们展示您的尝试和失败之处。我会使用模板化HTML。我要做的是有两个HTML文件,一个用于大部分固定的HTML,然后一个用于每行的模板。这会变得复杂,但我的观点是:对于不会改变的HTML,只要有一个具有基本结构的HTML文件,然后将要改变的部分有一个“scriptlet”。无论哪种方式,它都会变得复杂,难以调试。在某种程度上,您是在问一个调试问题。连接文本非常好。我一直在使用它,但我也喜欢用模板文本替换合并字段。例如:
var myOptionTemplate=“merge\u field\u For\u displated\u text”
然后使用
replace()
替换值:
var optionHtml=myOptionTemplate.replace(“my\u merge\u field\u For\u Value”,thisRowValue)
@SandyGood我还有其他html文件。这个表返回的很好,它只是为我遇到麻烦的第6列创建了内部。我不明白您正在显示的值和显示的文本的“我的合并”字段。就像else语句的第一行一样,它将所有6列都设为a,但我如何将其更改为仅设为5列,然后设为第6列a?
for (var j = 0; j < artistFileValues[i].length; j++)
    {
      if (isHeader)
      {
        table += "<th>" + artistFileValues[i][j] + "</th>\n"; //headers
        if (j == artistFileValues[i].length - 1) //if last header in row, add another cell with 'add' button
        {
          table += "<th style='text-align: center;'>" + "<a id='addButton' onclick=\x22addRow(this)\x22>" + "&plus;" + "</a>" + "</th>\n"; //'+' button
        }
      }
      else
      {
        if(j!==5)//I'm guessing this is the sixth column
        {
            table += "<td contenteditable='false'>" + artistFileValues[i][j] + "</td>\n"; //values
        }
        else
        {
            var s = mySelect(optionscsv,valuescsv);
            table += "<td contenteditable='false'>" + artistFileValues[i][j] + s + "</td>\n"; //values
        }
        if (j == artistFileValues[i].length - 1) //if last data in row, add another cell with 'delete' button
        {
          table += "<td style='text-align: center;'>" + "<a id='deleteButton' onclick=\x22deleteRow(this)\x22>" + "&times;" + "</a>" + "</td>\n"; //'x' button
        }
      }
    }