In the form, when the keyboard enters the Enter event, how to clear the text box and specify the current text box?
var str=[];
$("#ScanCode").keypress(function(event){
if(event.keyCode==13){
var ScanCodeId=$(this).val();
if (ScanCodeId==""){
return false;
}else {
//判断是否重复
for(var i in str){
if(str[i]===ScanCodeId){
alert('您的条码与当前申请明细重复,请重新选择!');
return false;
}
}
str.push(ScanCodeId);
$.ajax({
url: '${ctx}/returns/departmentReturn/json/barcode?barcode='+ScanCodeId,
async: false,
type: 'get',
cache: false,
dataType: 'json',
success: function (res) {
var data = res.rows;
if(data==""){
return false;
}else {
ScanRow('#departmentReturnDetailsList', departmentReturnDetailsRowIdx, departmentReturnDetailsTpl, data);
departmentReturnDetailsRowIdx = departmentReturnDetailsRowIdx + 1;
}
}
});
$(this).val('');
}
$("#returnReason").blur();
$("#ScanCode").focus();
}
})
Here is the whole code, please solve it. . .
某草草2017-05-19 10:47:52
event.keyCode==13 This is used to determine carriage return
.val("");//can be used to clear
.focus();//This is the event to get focus