所以现在我正在处理一个列表,您可以动态地添加内容。所以到目前为止我有这段代码,这是我的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中将,
全部设置为自定义字体。但是,当您输入要添加到列表中的内容时,它会键入自定义字体,但是最后添加到appendChild时,它将不再具有自定义字体。
最佳答案
第一个元素的文本包装在一个粗体标签中,后面没有添加。
如果要使列表项变为粗体,则最好的方法是使用CSS设置所有列表项元素的font-weight属性:
li {
font-weight : bold;
}