首页 > js 怎么自動提交表單

js 怎么自動提交表單

<script type="text/javascript">
$(function(){
    $('[name=weight]').val('1245788');
    $('#f').submit();
})
</script>
<form action="" method="" id="f">
<input type="text" value="" name="weight">
</form>

设置了值后就触发提交事件,楼主这个操作逻辑是不是有问题


如果只是想按enter键提交的话,可以设置监听一下这个键的keydown事件


通过判断 keyCode的值进行判断!在onmouseup的时候


<script type="text/javascript">
$(function(){
    $('[name=weight]').val('1245788');
    $('#f').submit(); // this is the key which tells the browser to submit now. 
})
</script>
<form action="" method="" id="f">
<input type="text" value="" name="weight">
</form>

检测keyup事件。可以这样搞:

HTML:

<input type='text' id='textArea'/> 

JS:

$('#textArea').bind("enterKey",function (e) {
   alert(e);
});

$('#textArea').keyup(function (e) {
    if(e.keyCode == 13) {
        $(this).trigger("enterKey");
    }
});

Fiddle Demo: https://jsfiddle.net/dspemhbr/


这是不可能的,放弃了

【热门文章】
【热门文章】