繁体   English   中英

在无序列表中创建元素

[英]creating elements inside an unordered list

我有一个在表单中创建无序列表的函数。 我有另一个功能,应该根据选择框的选定值将项目添加到列表中。 第二个函数将项添加到列表中,它们具有相应的id和whatnot,但没有文本。 无论我尝试什么,我都无法让物品中有文字。 这是javascript函数的当前内容。

function anotherItem()
{

var textValue = document.forms['newForm'].selectBox1.value;
var ul = document.getElementById("newList");    
var new_item = document.createElement("li");
new_item.id = textValue;
new_item.innerHtml = textValue; // I've also tried new_item.value = textValue among variations.
ul.insertBefore(new_item, ul.firstChild);


}
5|    new_item.innerHtml = textValue; 
 |                  └┬─┘
 |                   └───Should be "HTML"

JavaScript区分大小写。 现在textValue应该写在create li

(如果你在控制台中查看,如果你innerHtml应该创建一个错误。)

测试出来: http //jsfiddle.net/DerekL/svUqG/

暂无
暂无

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

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