簡體   English   中英

iOS Safari / Chrome Jquery / Javascript不起作用

[英]iOS Safari/Chrome Jquery/Javascript not working

我有一個基本的測試頁面:

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous">></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  </head>
  <body>
    <div class="col-xs-12 col-sm-8 col-md-6 col-lg-2">
    <p>Test</p>
      <form name="scan">
        Field 1
        <br>
        <input type="text" name="first" id="first">
        <br>
        Field 2
        <br>
        <input type="text" name="second">
        <br>
        Field 3
        <br>
        <input type="text" name="third">
        <br>
        <br>
        <input type="submit" name="submit">
      </form>
    </div>
    <script>
      $( document ).ready(function() {
        $("input:text:visible:first").focus();
      });
    </script>
  </body>
</html>

它可以在所有Windows瀏覽器中正常運行。

將Jquery代碼加載到具有最新iOS的iPhone上的Safari或Chrome中時,該代碼不起作用。

我也嘗試過:

document.getElementById("first").focus();

我還在命令周圍放了一些警報,這些警報起作用了,但焦點並沒有出現在第一個字段中。

我要去哪里錯了?

謝謝

你有這個代碼

$("input:text:visible:first").focus();

您要focus於第一個文本input 您可以這樣做:

$("input[type=text]:first").focus();

在方括號內的地方,選擇器指定type屬性的值,我們使用:first presudo-selector。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM