setAttribute是在input元素中设置list = <id datalist>的唯一选项吗?

CJD*_*CJD 5 javascript html5 attributes setattribute html-datalist

我很高兴设置list元素的list属性.

var sel = document.createElement("input");
sel.type = "text";
sel.id = "inputSelectNaam";
sel.list = "inputNamesList";
Run Code Online (Sandbox Code Playgroud)

当然这不起作用,因为list属性不是我想要的"list = {id for datalist}".使这项工作的唯一方法是使用setAttribute.

如何在不使用setter但直接更改属性的情况下解决此问题?

编辑:更好的代码段.

sel.list = id,我也提到过,在我的代码中不起作用.

var sel = document.createElement("input");
sel.type = "text";
sel.id = "inputSelectNaam";
sel.list = "inputNamesList"; //Does not work.
//sel.setAttribute("list", "inputNamesList"); //Works
sel.name = "name"; //FIXME: We should reconsider the name name...
frm.appendChild(sel);

var datl = document.createElement("datalist");
datl.id = "inputNamesList";
//populating the dataList
frm.appendChild(datl);
Run Code Online (Sandbox Code Playgroud)

当我查看Dragonfly时,我看到setAttribute("list",id)没有设置list属性.