2017-05-27 38 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>

相關問題