manually trigger focus on input Iphone issue

前端 未结 1 1166
不思量自难忘°
不思量自难忘° 2021-01-18 11:30

I am trying to focus a textarea after a click on a another element. desktop browsers seems to be working fine but not the Iphone.

$(\'.reveal_below\').on(\'c         


        
1条回答
  •  遇见更好的自我
    2021-01-18 11:43

    You have to use touchstart event to fix this issue.

    $(document).ready(function() {
    
      $('button').on('click', function() {
        $('#x').css({
          'margin-top': '0px',
          display: 'block',
          opacity: '0'
        }).animate({
            'margin-top': '15px',
            opacity: '1'
          },
          100
        )
    
        $('#x').trigger('touchstart'); //trigger touchstart
      });
    
      $('textarea').on('touchstart', function() {
        $(this).focus();
      });
    
    });
    
    
    
    
    
    

    0 讨论(0)
提交回复
热议问题