2017-05-27 36 views

回答

0

在提交表单之前您必须阻止使用jquery进行表单提交,并且必须迭代表中的每一列以获取值并设置在某个隐藏字段中并通过jQuery提交表单。

+0

u能请您分享一些示例代码? – Leeza

0

下面的代码遍历表值。这些值必须插入到表单中的某个输入字段中,或者以对象形式形成某些表单数据,并将其设置在表单中的输入字段中。

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<script> 
 
$(document).ready(function(){ 
 
    $("#submit").click(function(e){ 
 
     e.preventDefault(); 
 
     $("#tbody tr td").each(function(){ 
 
     \t alert($(this).text()); 
 
     }); 
 
     /* 
 
     SET VALUES EITHER IN INPUT FIELD OF FORM NEW FORM DATA AND SET IN A INPUT FIELD. 
 
     
 
     */ 
 
     $("#submit").unbind("click").click(); 
 
    }); 
 
}); 
 
</script> 
 
</head> 
 
<body> 
 
<form method="post" id="form"> 
 
<table id="table"> 
 
<thead> 
 
<tr> 
 
<th>Name</th> 
 
<th>Country</th> 
 
</tr> 
 
</thead> 
 
<tbody id="tbody"> 
 
<tr> 
 
<td>Harry</td> 
 
<td>USA</td> 
 
</tr> 
 
<tr> 
 
<td>Jonathan</td> 
 
<td>Germany</td> 
 
</tr> 
 
</tbody> 
 
</table> 
 
<input type="submit" value="submit" id="submit"/> 
 
</form> 
 
</body> 
 
</html>

相关问题