jquery focus not working on a page loaded with ajax

前端 未结 3 522
灰色年华
灰色年华 2021-01-28 00:41

My code

index.php





        
相关标签:
3条回答
  • 2021-01-28 01:17

    As your Ajax code knows all about the inputs (same page), why not just do this:

      success: function(msg)
      {
          $("#risultati").html(msg);
          $("#zio").focus();
      },
    

    Your current version has a child page has knowledge of the parent page (bad separation).

    0 讨论(0)
  • 2021-01-28 01:18

    You do not need to display the html code in go.php after you finish processing the POST data

    Try this

    $(document).ready(function() {
      $("#verifica").click(function(){
      $("#risultati").html("Please wait...");
        $.ajax({
          type: "POST",
          url: "go.php",
          data: $("#ciao").serialize(),
          //dataType: "html",
          success: function(msg)
          {
            $("#risultati").html(msg);
            $("#zio").focus();
          },
          error: function()
          {
              $("#risultati").html("An error occurred.");
          }
        });
      });
    });
    
    0 讨论(0)
  • 2021-01-28 01:18

    ADDITIONAL SOLUTION Had same issue where focus() didn't seem to work no matter what I tried.

    Eventually turned out that what was needed was scrolling to the correct position:

    • jQuery scroll to element
    • $(window).scrollTop() vs. $(document).scrollTop()
    0 讨论(0)
提交回复
热议问题