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;
}
精彩评论