2014-02-15 49 views
0

我使用下面的代碼通過URL填充表單,但是可以修改它以自動提交表單嗎?從URL填充html表單並自動提交

<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(function() { 
    // grab the entire query string 
    var query = document.location.search.replace('?', ''); 

    // extract each field/value pair 
    query = query.split('&'); 

    // run through each pair 
    for (var i = 0; i < query.length; i++) { 
     // split up the field/value pair into an array 
     var field = query[i].split("="); 

     // target the field and assign its value 
     $("input[name='" + field[0] + "'], select[name='" + field[0] + "']").val(field[1]); 
    } 
}); 
</script> 
</head> 
+0

無論你的表單id是否調用'submit'方法。 – Thunda

回答

0

您只需要將此行添加到腳本的底部,而不是使用表單的ID。

$("#MyFormId").submit();