简体   繁体   English

如何动态创建带有数据列表的输入?

[英]How to create an input with datalist dynamically?

I'm trying to create dynamycally some datalists. 我正在尝试动态创建一些数据列表。 My problem happen when I try to embed it in an input. 当我尝试将其嵌入输入中时会发生我的问题。 I tried this code but newinput.list="DL" doesn't work. 我尝试了这段代码,但newinput.list="DL"不起作用。 () ()

var newinput = document.createElement("input");
    newinput.className="nom";
    newinput.id= file_header[i];
    newinput.type= "text";
    newinput.list="DL";

document.getElementById("head_menu").appendChild(newdiv);

Input is created but without list attributes... Can someone explain me how to link my input with my datalist? 输入已创建但没有list属性...有人可以解释我如何将输入与数据list链接吗?

Try what @David is saying .. it worked for me. 尝试@David所说的..它对我有用。

newinput.setAttribute('list', 'DL'); newinput.setAttribute('list','DL');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM