我正在尝试在服务器端构建动态表单,然后再使用应用程序脚本注入(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/