focus() doesn't work inside colorbox pop-up

前端 未结 6 1741
遇见更好的自我
遇见更好的自我 2021-02-14 11:43

I tried to use focus for first input field on the form. but it doesn\'t work. When I call attr(\"id\") for that input it worked. When I call focus f

6条回答
  •  野的像风
    2021-02-14 12:38

    I've just stumbled on this problem.

    I think it's best to have a single $.colorbox opener like this:

        function showActionForColorBox(
           _url,
           _forFocus
       ) {
       $.colorbox(
             {
                scrolling: false,
                href: _url,
                onComplete: function () {
                   idColorboxAjaxIndect1.appendTo($('#cboxOverlay'));
                   idColorboxAjaxIndect2.appendTo($('#cboxOverlay'));
                   idColorboxAjaxIndect3.appendTo($('#cboxOverlay'));
                   idColorboxAjaxIndect4.appendTo($('#cboxOverlay'));
    
                   // --> Possible element's ID for focus
                   if (_forFocus) {
                      $('#' + _forFocus).focus();
                   }
                   return;
                },
                onCleanup: function () {
                   // TODO: ?
                   return;
                },
                onClosed: function () {
                   if (shouldReloadPageAfterColorBoxAction) {
                      // --> Should we reload whole page? 
                      shouldReloadPageAfterColorBoxAction = false; // NOTE: To be sure: Reset.
                      window.location.reload(false);
                   }
                   else if (cbEBillsActionReloadPopup) {
                      // --> Should we reload colorbox
                      cbEBillsActionReloadPopup = false;
                      showActionForColorBox(_url);
                   }
                   else if (cbShouldLoadAnotherContentAfterClosed) {
                      // --> Should we reload colorbox with custom content? 
                      cbShouldLoadAnotherContentAfterClosed = false;
                      $.colorbox({ html: setupContentForcbShouldLoadAnotherContentAfterClosed });
                      setupContentForcbShouldLoadAnotherContentAfterClosed = '';
                   }
                   return;
                }
             }
             );
    
       return;
    }
    

提交回复
热议问题