因此,现在我正在处理一个列表,您可以动态地向其中添加内容。到目前为止,我有这段代码,这是我的javascript
$("#textBox").keypress(function(e) {
if(e.keyCode == 13)
addToSticky();
});
function addToSticky() {
if(count < 5){
var text = document.getElementById("textBox").value;
var node = document.createElement("LI");
var textnode = document.createTextNode(text);
node.appendChild(textnode);
document.getElementById("list").appendChild(node);
count = count + 1;
}else
hideBox("textBox");
}这是我的html
<a href="#" class="sticky" STYLE="text-decoration: none">
<h2 STYLE="font-size:200%; font-weight:bold; padding-bottom:10px; margin-top: 4px">
Notes
</h2>
<p>
<ul id="list" STYLE="padding-left: 20px">
<li> <b>Hire this guy! </b></li>
</ul>
<input type="text" name="input" id="textBox">
</p>
</a>最后但并非最不重要的是,在我的css中,、< li >和< h2 >都将字体样式设置为自定义字体。但是,当您输入要添加到列表中的内容时,它会以自定义字体输入,但当它最终添加时,在appendChild处,它不再具有自定义字体。
发布于 2015-04-25 05:09:17
第一个元素的文本包含在一个粗体标记中,后面添加的元素没有。
如果要将列表项设置为粗体,最好的方法是使用CSS设置所有列表项元素的font-weight属性:
li {
font-weight : bold;
}发布于 2015-04-25 05:24:36
插入以下行
var font = document.createElement("b");
node.appendChild(font);之后
var textnode = document.createTextNode(text)请参阅http://jsfiddle.net/1e8zzLep/
https://stackoverflow.com/questions/29857393
复制相似问题