jQuery在点击时从用户输入创建列表项

web*_*rks 5 html javascript jquery

嗨,我需要一些帮助.请参阅下面的代码.在此先感谢您的任何帮助.

$('#input_listName').keyup(function(){
var newList = $(this).val();

$('#btn_createList').click(function(){
    ('.ul_current').append().html(newList);
});
});
Run Code Online (Sandbox Code Playgroud)
<input type="text"  id="input_listName"/>
<br/>
<button type="submit" class="btn_sendMessage" id="btn_createList">Create List</button>

<ul class="ul_current">
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

jAn*_*ndy 7

$('#btn_createList').click(function(){
    $('.ul_current').append($('<li>', {
         text: $('#input_listName').val()
    }));
});
Run Code Online (Sandbox Code Playgroud)

应该这样做.

演示:http://www.jsfiddle.net/G8pbG/