How to always focus keep focus in text box

后端 未结 2 1541
故里飘歌
故里飘歌 2021-02-11 05:02

I have created a single HTML page that contains two divs. The div on the left (90% of page) is the target for ajax results. The div on the right (10% of page) contains a single

2条回答
  •  臣服心动
    2021-02-11 05:40

    Using jQuery would look something like this:

    $(function() {
         // Focus on load
         $('.scanner').focus();
         // Force focus
         $('.scanner').focusout(function(){
             $('.scanner').focus();
         });
         // Ajax Stuff
         $('.scanner').change(function() {
             $.ajax({
                 async: true,
                 cache: false,
                 type: 'post',
                 url: '/echo/html/',
                 data: {
                     html: '

    This is your object successfully loaded here.

    ' }, dataType: 'html', beforeSend: function() { window.alert('Scanning code'); }, success: function(data) { window.alert('Success'); $('.objectWrapper').append(data); }, // Focus complete: function() { $('.scanner').val('').focus(); } }); }); });

    jsFiddle example: http://jsfiddle.net/laelitenetwork/fuMYX/5/

    P.S: jQuery haters gonna hate ;).

提交回复
热议问题