$("#title").keypress(function(event){
if(event.which == 13){
$("#nextField").focus();
}
});
问:如何关注 #details
而不在 #title
的值中留下尾随 \n
?
尝试失败:
$("#title").keypress(function(event){
if(event.which == 13){
$(this).val($(this).val().replace(/\n/g,""));
$("#nextField").focus();
}
});
最佳答案
你想要的是 event.preventDefault();
$("#title").keypress(function(event){
if(event.which == 13){
$("#details").focus();
event.preventDefault();
}
});
关于javascript - 如何通过测试 event.which == 13 来关注下一个字段,而不在当前字段中留下尾随\n?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4558288/