繁体   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