Javascript 动态生成一个?

Javascript 动态生成一个?,javascript,jquery,Javascript,Jquery,单击此按钮,将显示带有文本字段的列表项 <span id="n-email" class="email-btn"><a href="#."></a></span> 假设我在这个输入字段中填写了一些内容,然后按enter键。 按enter键时,我想触发一个事件,该事件将 删除包含输入字段的。 在其位置插入新的,如 <li id="new" class="select"> <a> <input t

单击此按钮,将显示带有文本字段的列表项

<span id="n-email" class="email-btn"><a href="#."></a></span>
假设我在这个输入字段中填写了一些内容,然后按enter键。 按enter键时,我想触发一个事件,该事件将

删除包含输入字段的。 在其位置插入新的,如

<li id="new" class="select">
    <a>
        <input type="text" id="emails" class="add-email" value="Untitled" onfocus="if(this.value=='Untitled'){this.value=''}" onblur="if(this.value=='')  {this.value='Untitled'}"/>
    </a>
</li>

你可以试试这个。。但您必须将其修改为示例值:

<li>
    <a href="#.">
        //here comes the value what we entered in the input field of above li//
    </a>
</li>

首先,需要隐藏新行,然后需要使用keypress事件捕捉enter键,最后使用append方法插入新元素

下面是一个基于脚本的示例

$('li').each(function() {
    var input = $(this).find('input');
    $(this).append(input.val());
    input.remove();
});

到目前为止你试过什么吗?至少在jsfiddle.net上试一试,直到有人得到超过500个代表,在问题表单中应该有一个部分要填写,包括谷歌搜索尝试最少3次和一个jsfiddle链接。啊啊啊啊,够了这种填鸭式的喂食。有人甚至连“请”都不说!
$(".email-btn").click(function() {
    $("#new").show();
});

$("#emails").keypress(function(e)
{
    value = $(this).val();
    code= (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
        $("#new").remove();
        $("#mylist").append("<li><a>"+value+"</a></li>");
    }

});