Jquery从特定表单中选择输入 [英] Jquery to select input from specific form
本文介绍了Jquery从特定表单中选择输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个页面中有几个表单,我需要在单击提交按钮的表单上选择输入并通过ajax将其发送到php页面。
这就是我所拥有的:
I have several forms in one page, I need to select the inputs on the form where the submit button is being clicked and send it via ajax to a php page.
This is what I have:
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$(document).ready(function(){
$('[name="Submit"]').click(function() {
var $this = $(this);
var tzip = 'zip=' + $this.parent().find('#zip').val() + '&Date1=' + $this.parent('form').find('Date1').val() + '&Date2=' + $this.parent('form').find('#Date2').val() + 'Date3=' + $this.parent().find('#Date3').val() + '&Date4=' + $(this).find('#Date4').val() + 'Date5=' + $(this).find('#Date5').val() + '&Date6=' + $(this).find('#Date6').val();
alert (tzip);
$.ajax({
url: 'updateZipcodes.php?',
data: tzip,
dataType: 'html',
cache: false,
type: 'GET',
success: function(response) {
successCallback(response);
}
});
function successCallback(responseObj){
//do something like read the response and show data
$('#ZipsResult').html(responseObj);
}
});
});
</script>
所有表格都是这样的:
All the forms look like this one:
<form id="form" name="form" >
<th>20723</th>
<td><input name='Date1' id='Date1' type='text' value='' maxlength='10' size='10' /></td>
<td><input name='Date2' id='Date2' type='text' value='' maxlength='10' size='10' /></td>
<td><input name='Date3' id='Date3' type='text' value='' maxlength='10' size='10' /></td>
<td><input name='Date4' id='Date4' type='text' value='' maxlength='10' size='10' /></td>
<td><input name='Date5' id='Date5' type='text' value='' maxlength='10' size='10' /></td>
<td><input name='Date6' id='Date6' type='text' value='' maxlength='10' size='10' /></td>
<td><input name="zip" id="zip" type="hidden" value="20723" /><input name='Submit' type='button' value='Submit' /></td>
</form>
我得到'zip'输入的值但不是以下输入。我怎样才能解决这个问题 ?谢谢,
I get the value for the 'zip' input but not the following inputs. How can I fix this ? Thanks,
推荐答案
(document).ready(function(){
(document).ready(function(){
('[name =Submit]' ).click(function(){
var
('[name="Submit"]').click(function() { var
this =
这篇关于Jquery从特定表单中选择输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文