在表單中,鍵盤(pán)輸入回車事件,如何清空文字方塊並製定當(dāng)前文字方塊?
var str=[];
$("#ScanCode").keypress(function(event){
if(event.keyCode==13){
var ScanCodeId=$(this).val();
if (ScanCodeId==""){
return false;
}else {
//判斷是否重復(fù)
for(var i in str){
if(str[i]===ScanCodeId){
alert('您的條碼與當(dāng)前申請(qǐng)明細(xì)重復(fù),請(qǐng)重新選擇!');
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();
}
})
這裡是全部程式碼,求解。 。 。
event.keyCode==13這個(gè)是判斷回車的
.val("");//可以用來(lái)清空
.focus();//這個(gè)是獲取焦點(diǎn)的事件