您需要将复制的代码部分更改为:
$('.form').on('keyup', '.accepted', function(e) {
if (e.which == 13) {
var line = $(this).parent(); // this targets '.line'
//this targets line's "container", which is '.copy', then find all the .current's in the next node (.line)
var current = $(line).parent().next().find('.current');
//as var current returns a list with all the .current's found, even if there's only one, it returns an array of elements in case there were more, so we select the first one from the array
current = $(current)[0];
$(current).focus();
}
});
说明:由于.accepted是文档加载后创建的类,绑定keyup函数时不存在
您需要使用 on() 代替,定位“.accepted”,
我已经分解了如何找到您想要的“.current”以便您理解它,但实际上您可以通过多种方式找到它。我使用了我认为更容易理解的那个,这是一个工作小提琴的链接:http: //jsfiddle.net/QaHB3/1/