javascript - Form text box keyboard enter event, how to clear the text box and specify the current text box?
習慣沉默
習慣沉默 2017-05-19 10:45:52
0
1
584

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. . .

習慣沉默
習慣沉默

reply all(1)
某草草

event.keyCode==13 This is used to determine carriage return

.val("");//can be used to clear

.focus();//This is the event to get focus

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!