【发布时间】:2019-09-23 09:04:38
【问题描述】:
我需要将回调的值添加到我的 setAttribute 中。我怎么做?
这个值是稍后从表中取出数据所必需的。
这是代码:
row.forEach(function(row) {
var subchapname = document.createElement("div");
subchapname.setAttribute("id", "subchaptertitle");
subchapname.setAttribute("subid", '"+row+"');
subchapname.setAttribute("onclick","{ alert('You are not going to believe this!') } ");
subchapname.textContent = row.subname;
rows.appendChild(subchapname);
基本上,这意味着: 回调 = 行
这个回调需要添加到subchapname.setAttribute("subid", '"+row+"');
这可能吗?
这是实际结果:
<div id="subchaptertitle" subid=""+row+"" onclick="{ alert('You are not going to believe this!') } ">bos in brand</div>```
【问题讨论】:
-
您希望“subid”属性最终包含什么值?行回调实际上并没有返回值,它只是设置了一堆属性,然后在 div 中附加一些文本。
-
感谢您的回复 :) 我实际上需要该行中的 id(我称之为 subid)。该行以这种方式来自 sqlite 数据库:
db.all("SELECT subname FROM chaptree WHERE (chapname='" + chapname + "') ORDER BY suborder", function(err,row) -
你应该可以做到
subchapname.setAttribute("subid", row)或subchapname.setAttribute("subid", row.someProperty)row有什么样的数据结构?您可以控制台记录并更新问题吗?
标签: javascript node.js sqlite electron setattribute