开发者

Cloning DIVs and setting parameters around children

I'm working with a function that duplicates a text input field and it开发者_运维知识库's containing div when the return key is hit. The div clones correctly with the input element, but does anyone have suggestions on how to clear the contents of that input element and focus on it?

JavaScript:

if (event.keyCode == 13) {
        var currentInput = $(this).parent("div");
        currentInput.clone().val('').insertAfter(currentInput).focus();
        return false;
}

HTML:

    <div id="item_container">   
        <input type="text" class="data-entry">
    </div>


try this;

if (event.keyCode == 13) {
    var currentInput = $(this).parent("div");
    currentInput.clone().insertAfter(currentInput).find('.data-entry').val('').focus();
    return false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜