开发者

Cloning DIVs and setting parameters around children

开发者 https://www.devze.com 2023-03-14 03:00 出处:网络
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 h

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

精彩评论

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

关注公众号