2013-02-18 69 views
1

我想实现复选框作为表单提交,但我意识到它不会这样工作。什么是实施这个的正确方法?我在这里读了一些例子,但无法理解。我的jQuery DataTable复选框不工作,我做错了什么?

<form method="post" name="search_form" action="<?php echo $linksearch; ?>"> 
<table cellpadding="0" cellspacing="0" border="0" class="display" id="search_table"> 
<thead> 
<tr> 
<th>Process1</th> 
<th>Process2</th> 
<th>Process3</th> 
<th>Process4</th> 
<th></th> 
</tr> 
</thead> 
<tbody> 
<?php 
$sql = "select * from activity_temp"; 
$result=tep_db_query($sql); 
$sc=0; 
while($row = mysql_fetch_array($result)){ 
    echo "<tr>"; 
    echo "<td>".$row['p1']."</td>"; 
    echo "<td>".$row['p2']."</td>"; 
    echo "<td>".$row['p3']."</td>"; 
    echo "<td>".$row['p4']."</td>"; 
    echo "<td class=\"center\"><input type=\"checkbox\" name=\"search_cb[".$row['temp_id']."]\" value=\"on\"></td>"; 
    echo "</tr>"; 
$sc++; 
} 
?> 
</tbody> 
<tfoot> 
<tr><td colspan="5" align="right"> 
<input id="search_form_submit" type="submit" name="submit" value="Search" class="submit" /> 
</td></tr> 
</tfoot> 
</table> 
</form> 

我会这样做吗?

$('#search_table').dataTable({ 
    "aoColumnDefs": [{ 
     "bSortable": false, "aTargets": [4] 
    }], 
    "aoColumns": [ 
    { "mDataProp": "checkBox" }], 
      "aaData": [{ 
     "checkBox": "<input type="checkbox" name="search_cb" value="on" />" 
    }]   
}); 
+1

如果你的JavaScript代码看起来真的这样,至少一个原因,它不工作是在'checkBox'属性不一致使用引号。可以使用双引号或在双引号内使用单引号。 – 2013-02-18 18:23:21

回答

1
$('#form').submit(function() { 
    var sData = $('input', oTable.fnGetNodes()).serialize(); 
    alert("The following data would have been submitted to the server: \n\n"+sData); 
    return false; 
}); 

来源:http://datatables.net/examples/api/form.html

相关问题