Php 特定行的Jquery html()
我已经用typeselect、nametext、unitselect创建了动态行,我正在为onchange类型的select编写代码。 但当我从类型字段更改值时,它已将值加载到当前行名称字段中,并将选项动态加载到当前单位选择字段中, 将值加载到活动行可以正常工作,但将选项加载到选择单位则不行 我的代码如下Php 特定行的Jquery html(),php,jquery,html,Php,Jquery,Html,我已经用typeselect、nametext、unitselect创建了动态行,我正在为onchange类型的select编写代码。 但当我从类型字段更改值时,它已将值加载到当前行名称字段中,并将选项动态加载到当前单位选择字段中, 将值加载到活动行可以正常工作,但将选项加载到选择单位则不行 我的代码如下 $(document).on('change', '.raw', function () { // var r = this.val(); if ($(this).val()
$(document).on('change', '.raw', function () {
// var r = this.val();
if ($(this).val() != 0) {
var t = $(this).parents('tr').find(".raw :selected").text();
$(this).parents('tr').find(".name").val(t);
下面是我需要帮助的地方
$(this).parents('tr').find(".amount").html(data); -> here i need help
// $(".amount").html(data); ->this working fine but change all the select value
提前谢谢。
这是我桌子的完整编码
<table id="addingtable" class="table table-bordered">
<tr>
<th>Raw Master</th>
<th>Name</th>
<th>Display</th>
<th>Value</th>
<th>Unit</th>
<th>Delete</th>
</tr>
<tr>
<td><select name='rawmaster[]' class = 'form-control raw' required><option>Select</option><?php echo rawmaster_item($conn,$type); ?><option value="0">None</option></select></td>
<td><input type='text' name='name[]' placeholder="Name" class = 'form-control name' required /></td>
<td><select name='des[]' class = 'form-control' required><option>Select</option><option Value = 'y'>Yes</option><option Value = 'n'>No</option></select></td>
<td><input type='text' name='value[]' placeholder="Value" class = 'form-control' required /></td>
<td><select name='amount[]' class = 'form-control amount' required><option>Select</option><?php echo $output2; ?></select></td>
<td><button type='button' class='btn btn-icon btn-danger remove'><i class='feather icon-trash-2'></i></button></td>
</tr>
我可能错了,但我认为您需要在ajax请求上设置上下文,否则将引用不同的上下文回调,添加上下文:如下所示:
$.ajax({
url:"plandetails_getunit.php",
method:"POST",
data:"id="+r,
context:this,
success:function(data)
{
你能说得更具体些吗?如果你能把所有的代码都贴出来great@Claudio我正在发布我的完整代码
$(document).on('change', '.raw', function () {
// var r = this.val();
if ($(this).val() != 0) {
var t = $(this).parents('tr').find(".raw :selected").text();
$(this).parents('tr').find(".name").val(t);
$(this).parents('tr').find(".name").attr("readonly", "TRUE");
var r = $(this).parents('tr').find(".raw").val();
// alert(r);
$.ajax({
url:"plandetails_getunit.php",
method:"POST",
data:"id="+r,
success:function(data)
{
if(data)
{
$(this).parents('tr').find(".amount").html(data); => need help here
// $(".amount").html(data);
}
}
});
}
else{
$(this).parents('tr').find(".name").val('');
$(this).parents('tr').find(".name").removeAttr("readonly");
var r = $("#ptype").val();
$.ajax({
url:"plandetails_getunit1.php",
method:"POST",
data:"id="+r,
success:function(data)
{
if(data)
{
// $(".amount").html(data);
$(this).parents('tr').find(".amount").val(); =>here remains work gud
}
}
});
}
});
$.ajax({
url:"plandetails_getunit.php",
method:"POST",
data:"id="+r,
context:this,
success:function(data)
{