我有一张桌子并用ajax填充<
> TABLE
<table id="tabla_productos"> </table>
Ajax源数据
var tabla_productos = $('#tabla_productos').DataTable( {
"responsive" : "true",
"ajax": {
"url": "/funciones/getProductos.php",
"dataSrc": ""
},
"columns": [
{ "data": "id" },
{ "data": "add_cart" }
]
}});
AJAX DATA
{"id":"2",
"add_cart":"<form class=\"form-item\"><input type=\"hidden\" value=\"1\" name=\"product_qty\"><input type=\"hidden\" value=\"S10881\" name=\"product_code\"><button class=\"btn\" type=\"submit\">Add to Cart<\/button><\/form>" }
jQuery表单提交:
$(".form-item").submit(function(e){
alert('ok');
e.preventDefault();
});
HTML OUTPUT:从ajax
创建的表单<form class="form-item"><input type="hidden" name="product_qty" value="1"><input type="hidden" name="product_code" value="S10881"><button type="submit" class="btn">Add to Cart</button></form>
从HTML创建的相同表格:
<form class="form-item"><input type="hidden" name="product_qty" value="1"><input type="hidden" name="product_code" value="S10881"><button type="submit" class="btn">Add to Cart</button></form>
如果我等待那个表填满数据,它就可以了:
的setTimeout(函数(){
$( “表单项”)。提交(函数(E){
警报( 'OK');
e.preventDefault();
});
},10000);
答案 0 :(得分:0)
我添加了&#34; initComplete&#34;使用表单提交功能到数据表
var tabla_productos = $('#tabla_productos').DataTable( {
"responsive" : "true",
"ajax": {
"url": "/funciones/getProductos.php",
"dataSrc": ""
},
"columns": [
{ "data": "id" },
{ "data": "add_cart" }
],
"initComplete": function(settings, json) {
$(".form-item").submit(function(e){
alert('ok');
e.preventDefault();
});
}
}});