簡體   English   中英

JavaScript自動提交表單不起作用

[英]Javascript auto submit form not work

我的代碼有問題..我希望在填寫長度為10位數字的文本框后使其自動提交。

這是我的JavaScript代碼

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>

    $("#idnya").on("input propertychange", function()
        {
            if($(this).val().length ==15){
            $("#max").submit()
        }
    });

    </script>

</script>

這是我的PHP代碼

<?php
include "koneksi.php";

echo"

<body>
    <form id=max name='cingcing' action='lanjut.php' method='POST'>
    <center>

        <table>
        <tr>
            <td colspan=2> <center> id </center> </td>
        </tr>
        <tr>
            <td> id number </td> <td> <input type=password id='idnya' name='idnya2'> </td> 
        </tr>
    </center>
    </form>
</body>
";
?>

在文檔“就緒”之前,無法安全地操縱頁面。 我認為您忘記了ready功能。 並且要檢查長度,您可以如下綁定keyup事件。

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#idnya").on("keyup",function(){
                if($(this).val().length == 10){
                    $("#max").submit();
                }
            });
        });
    </script>

這可能對你有幫助

    <?php
    include "koneksi.php";
    echo "
    <html><head></head>
    <body>
        <form id=max name='cingcing' action='lanjut.php' method='POST'>
        <center>

            <table>
            <tr>
                <td colspan=2> <center> id </center> </td>
            </tr>
            <tr>
                <td> id number </td> <td> <input type=password id='idnya' name='idnya2'> </td> 
            </tr>
            </table>
        </center>
        </form>

    </body>
    </html>";
    ?>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>

        $("#idnya").on("input propertychange", function()
        {
            if ($(this).val().length == 15) {
                $("#max").submit()
            }
        });

    </script>

只需使用此更改腳本

$("#idnya").on("input propertychange", function()
    {
        if($(this).val().length ==10){
        $("#max").submit()
    }
});

</script>

JSFIDDLE演示是在這里進行keyup或更改

  $("#idnya").keyup(function()
    {
        if($(this).val().length ==15){
        $("#max").submit()
    }
  });

//或者使用USE CHANGE,當您專注於離開時它將運行

  $("#idnya").change(function()
    {
        if($(this).val().length ==15){
        $("#max").submit()
    }
  });

暫無
暫無

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

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