$('.gradeX').on("focusout","input.musteri_no",function(){
var deger = "musteri_no=" + $(this).val();
$.ajax({
url: 'musteri_script.php',
data: deger,
type: 'post',
dataType: 'json',
success : function(cevap) {
if (cevap.ok) {
$(this).find("#ts").val(cevap.ok.TS);
$(this).find("#ts").attr("readonly", true);
} else {
}
}
});
});
这里是html:
<tr class="odd gradeX" style="font-size:12px;">
<td style="width:75px;"><select name="tahsilat_turu[]" class="form-control mb15 tahsilat_turu">
<option value = "-1">Tahsilat Türü Seçin</option>
<option value = "0">Kredi Kartı </option>
<option value = "1"> Nakit </option>
<option value = "2"> Çek </option>
</select></td>
<td><input type="text" name="belge_no[]" value="" class="form-control" /></td>
<td><input type="text" name="musteri_no[]" value="" class="form-control musteri_no" /></td>
<td><input type="text" id="musteri_unvani" name="musteri_unvani[]" value="" class="form-control" /></td>
<td><input type="text" id="ts" name="ts[]" value="asd" class="form-control" /></td>
<td><input type="text" name="bolge[]" value="" class="form-control" /></td>
<td><input type="text" name="tutar[]" value="" class="form-control" /></td>
<td><input type="text" name="tahsilat_tarihi[]" value="" class="form-control datepicker" /></td>
<td><input type="text" name="banka[]" id = "banka" value="" class="form-control" /></td>
<td><input type="text" name="sube[]" id = "sube" value="" class="form-control" /></td>
<td><select name="banka_hesap_no[]" id="banka_hesap_no" style="width:90px;" class="form-control mb15">
<option value="-1">Banka Hesap Numarası</option>
<?php for ($i = 0; $i < count($hesapNumaraları); $i++) { ?>
<option value="<?php echo $hesapNumaraları[$i]["hesap_no"]; ?>"><?php echo $hesapNumaraları[$i]["hesap_no"]; ?></option>
<?php }//for ?>
</select></td>
<td><input type="text" name="vade[]" id = "vade" value="" style="width:40px;" class="form-control" /></td>
</tr>
如果我写$("#ts").val(cevap.ok.TS);
我可以访问
但我动态创建了更多tr
,如下所示:
$.ekle = function() {
$("#tbody").append("<tr class='odd gradeX' style='font-size:12px;'><td style='width:75px;'><select name='tahsilat_turu[]' class='form-control mb15 tahsilat_turu'><option value = '-1'>Tahsilat Türü Seçin</option><option value = '0'>Kredi Kartı </option><option value = '1'> Nakit </option><option value = '2'> Çek </option></select></td><td><input type='text' name='belge_no[]' value='' class='form-control' /></td><td><input type='text' name='musteri_no[]' value='' class='form-control' /></td><td><input type='text' id='musteri_unvani' name='musteri_unvani[]' value='' class='form-control musteri_no' /></td><td><input type='text' id='ts' name='ts[]' value='' class='form-control' /></td><td><input type='text' name='bolge[]' value='' class='form-control' /></td><td><input type='text' name='tutar[]' value='' class='form-control' /></td><td><input type='text' name='tahsilat_tarihi[]' value='' class='form-control datepicker' /></td><td><input type='text' name='banka[]' id = 'banka' value='' class='form-control' /></td><td><input type='text' name='sube[]' id = 'sube' value='' class='form-control' /></td><td><select name='banka_hesap_no[]' id='banka_hesap_no' style='width:90px;' class='form-control mb15'><option value='-1'>Banka Hesap Numarası</option> <?php for ($i = 0; $i < count($hesapNumaraları); $i++) { ?> <option value='<?php echo $hesapNumaraları[$i]['hesap_no']; ?>'><?php echo $hesapNumaraları[$i]['hesap_no']; ?></option> <?php }//for ?></select></td><td><input type='text' name='vade[]' id = 'vade' value='' style='width:40px;' class='form-control' /></td></tr>");
}
我可以从live select changed
访问不同的输入,如下所示:
$(".gradeX").live("change", 'select[class=tahsilat_turu]' , function() {
var secilen = $(this).find(":selected").val();
if (secilen == "0") {
$(this).find("#banka").attr("readonly", false);
$(this).find("#sube").attr("readonly", true);
$(this).find("#banka_hesap_no").attr("readonly", true);
$(this).find("#vade").attr("readonly", true);
} else if (secilen == "1") {
$(this).find("#banka").attr("readonly", true);
$(this).find("#sube").attr("readonly", true);
$(this).find("#banka_hesap_no").attr("readonly", false);
$(this).find("#vade").attr("readonly", true);
}else if (secilen == "2") {
$(this).find("#banka").attr("readonly", false);
$(this).find("#sube").attr("readonly", false);
$(this).find("#banka_hesap_no").attr("readonly", true);
$(this).find("#vade").attr("readonly", false);
}
});
但我不能&#39;在焦点中访问#ts
,我可以访问更改
当musteri_no聚焦时,我怎样才能访问哪个ts&#39; s musteri_no?
答案 0 :(得分:3)
success
回调函数将this
设置为等于Ajax事件。一个简单的解决方法是创建一个变量来保存以前的上下文:
$('.gradeX').on("focusout","input.musteri_no",function(){
// Store `this` and retrieve containing object
var $this = $(this);
var $gradeX = $this.closest(".gradeX");
var deger = "musteri_no=" + $this.val();
$.ajax({
url: 'musteri_script.php',
data: deger,
type: 'post',
dataType: 'json',
success : function(cevap) {
// Use containing object to find #ts
if (cevap.ok) {
$gradeX.find("#ts").val(cevap.ok.TS);
$gradeX.find("#ts").attr("readonly", true);
} else {
}
}
});
});