Javascript 输入一个ul
我想将ul作为输入,如下面的JSFIDLE: (但我不想使用Javascript 输入一个ul,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想将ul作为输入,如下面的JSFIDLE: (但我不想使用tagit,我想自己实现它) 我希望用户可以在输入中写入一些内容,当他按下enter键时,一个带有X按钮的li将插入到输入中 我真的不知道如何实现它 如果我知道如何将ul作为输入,我将知道如何做 请帮助我: 假设我有ul: <ul id="countries"></ul> 感谢您的帮助 使用contenteditable <ul id="countries" contenteditable="true"&
tagit
,我想自己实现它)
我希望用户可以在输入中写入一些内容,当他按下enter键时,一个带有X按钮的li将插入到输入中
我真的不知道如何实现它
如果我知道如何将ul作为输入,我将知道如何做
请帮助我:
假设我有ul:
<ul id="countries"></ul>
感谢您的帮助 使用contenteditable
<ul id="countries" contenteditable="true"></ul>
这就是你的意思吗
$('#countries').keypress(function(e) {
if(e.which == 13) {
var value; // here I have to get the value of the input
// insert the li to the ul:
var html = $(value).find("ul").append('<li value="1">' + value +
' <span class="closeButton">X</span></li>');
$("#countries").val(html);
}
});
$(“#国家”)。按键(功能(e){
如果(e.which==13){
var value;//这里我必须获取输入的值
//将li插入ul:
var html=$(value).find(“ul”).append(''+value+
"X",;
$(“#国家”).val(html);
}
});
您正在寻找此
?live
已被弃用并消失。使用$(文档)。在('click','.closeButton',…)
@JanDvorak上,您忘记添加链接了。谢谢!它不会将文本插入ul。。它是如此接近,但我想把它插入ul,而不是上面。。再次感谢你!
$('#countries').keypress(function(e) {
if(e.which == 13) {
var value; // here I have to get the value of the input
// insert the li to the ul:
var html = $(value).find("ul").append('<li value="1">' + value +
' <span class="closeButton">X</span></li>');
$("#countries").val(html);
}
});