javascript - 构建 HTML 时属性 ID 无效

标签 javascript html google-apps-script

enter image description here

我正在尝试在服务器端构建动态表单,然后再使用应用程序脚本注入(inject)客户端。

我必须使用字符串构建 html,因为在服务器端似乎没有一个带有应用程序脚本的良好模板系统。到目前为止我的 html 看起来像:

label <select id="DATE" name="DATE" type="text" value="myvalue"/> label <select id="FULLNAME" name="FULLNAME" type="text" value="myvalue"/> label <select id="STREET" name="STREET" type="text" value="myvalue"/> 

我的计划是用我使用屏幕截图中的代码生成的实际 html 标签替换“标签”

buildhtml 函数是:

// my little html string builder
function buildHTML(tag, html, attrs) {
  // you can skip html param
  if (typeof(html) != 'string') {
    attrs = html;
    html = null;
  }
  var h = '<' + tag;
  for (attr in attrs) {
    if(attrs[attr] === false) continue;
    h += ' ' + attr + '="' + attrs[attr] + '"';
  }
  return h += html ? ">" + html + "</" + tag + ">" : "/>";
}

如何解决这个问题

最佳答案

“for”是 JavaScript 中的保留关键字,因为它在某种循环中使用。浏览器可能会让您误用它作为属性 ID,但 Google Apps 脚本不会。将其放在引号中,无论如何,即使不需要,这对于字段名称来说也是一个好主意。

{"for": field}

关于javascript - 构建 HTML 时属性 ID 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46264317/

相关文章:

javascript - 为了获得良好的 SEO,我应该避免哪些 javascript 做法

html - 可打印选项卡按钮

google-apps-script - 使用变量时范围的坐标或尺寸无效

javascript - 拉拉维尔 5 : Get the default value of my select option with onChange event using Vue js

javascript - 删除 ul 标签的连续子代

javascript - 如何从异步调用返回响应?

javascript - 应用过滤器后元素被删除

html - 当将桌面网站缩放到 150% 以上时,它会恢复到移动响应模式

javascript - 将 Google Sheet 转换为多级 JSON 数组

oauth - Google App Script - 如何删除授予的 OAuth 权限?