我的代码有问题.. 我想让它在文本框中填写长度为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
函数。要检查长度,您可以绑定(bind) 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>
关于Javascript 自动提交表单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26709522/