嗨,伙计们,我在ajax中遇到了问题,我在php页面上使用了for-each循环来生成带有一些按钮的表行问题是post方法只返回第一行的id和其他attr如何获取other rows属性
这是密码
$('.erja').click(function() {
$('.load_erja').show();
$('.load_erja').css({
"background-color": "blue",
"color": "white"
});
$('.load_erja').html("process");
var id = $(".new_id").val();
var kar = $(".kar").val();
var reggg_sub = 'reggg_sub';
$.ajax({
type: 'POST',
url: 'check.php',
data: {
'id': id,
'kar': kar,
'reggg_sub': reggg_sub
},
success: function(html) {
eror(parseInt(html));
}
})
});
这是html代码
<div class="modal fade" id="edit_<?php echo $rows['id']?>" tabindex="-1" aria-hidden="true" aria-labelledby="#edit_<?php echo $rows['id']?>" role="dialog">
<div class="modal-dialog modal-me ">
<div class="modal-content">
<div dir="rtl" class="modal-body">
<form action="">
<div class="from-group">
<input class="new_id" id="new_id_<?php echo $rows['id']?>" type="text" value="<?php echo $rows['id']?>">
<select class="form-control kar" name="e" id="kar_<?php echo $rows['id']?>">
<option value="-1">test1</option>
<option value="1">test</option>
</select>
<a href="#" id="load_erja_<?php echo $rows['id']?>" type="button" class="btn btnnormal text-center load form-control load_erja "></a>
<a href="#" id="erja_<?php echo $rows['id']?>" type="button" class="btn btn-success btnnormal text-center submit form-control erja">ارجاع</a>
</div>
</form>
</div>
<div class="modal-footer">
<a href="#" type="button" data-dismiss="modal" aria-label="close" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> بستن</a>
</div>
</div>
</div>
</div>
<?php } ?>
</table>
我想在ajax上使用这个方法,但是它没有任何价值
$(this).children('input').attr(“id”);
最佳答案
我会用不同的方式:
创建这样的函数:
function CheckKar(idParam, karParam){
$('.load_erja').show();
$('.load_erja').css({
"background-color": "blue",
"color": "white"
});
$('.load_erja').html("process");
var id = $(".new_id").val();
var kar = $(".kar").val();
var reggg_sub = 'reggg_sub';
$.ajax({
type: 'POST',
url: 'check.php',
data: {
'id': idParam,
'kar': karParam,
'reggg_sub': reggg_sub
},
success: function(html) {
console.log(html);
}
});
}
然后在php中创建这些链接:
<a href='http://www.google.com' onclick='return CheckKar(0,"mercedes")' class='erja'>check</a>