- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我有一个关于 ajax 的问题。其中ajax无法获取第二行的数据。
function getdtbarang($barcode = FALSE) {
if ($barcode === FALSE)
{
$query = $this->db1->get('tblmstbarang');
return $query->result_array();
}
$query = $this->db1->get_where('tblmstbarang', array('barcode' => $barcode));
return $query->row_array();
}
function getdatabarang() {
$barcode = $this->input->post('barcode');
$data=$this->Mbarang->getdtbarang($barcode);
echo json_encode($data);
}
<script type="text/javascript">
function getdatabrg(barcode){
$('#barcode_2').each(function() {
var barcode =$('#barcode_2').val();
$.ajax({
type : "post",
data : "barcode=" +barcode,
url : "<?php echo base_url();?>index.php/master/barang/Cbarang/getdatabarang",
dataType:"json",
success: function(data){
for(var i in data)
{
var obj= data[i];
$("#barang_nama_2").val(obj.barang_nama);
$("#harga_beli_2").val(obj.harga_beli);
}}
});
});
}
$(document).ready(function() {
$('#barcode_2').keyup(function() {
getdatabrg();
});
});
</script>
<td><input type="text" class="form-control" id="barcode" name="barcode[]" value="<?php echo set_value('barcode['.$i.']') ;?>" onKeyUp="getValues()" ></td>
<td><input type="text" class="form-control" id="barang_nama" name="barang_nama[]" value="<?php echo set_value('barang_nama['.$i.']') ;?>" onKeyUp="getValues()" disabled></td>
<td><input type="text" class="form-control" id="harga_beli" name="harga_beli[]" value="<?php echo set_value('harga_beli['.$i.']');?>" onKeyUp="getValues()" disabled></td>
<td><input type="text" class="form-control" id="barcode_2" name="barcode[]" value="<?php $a=set_value('barcode[0]') ; echo $a;?>"></td>
<td><input type="text" class="form-control" id="barang_nama_2" name="barang_nama[]" value="<?php $a=set_value('barang_nama[0]') ; echo $a;?>" onKeyUp="getValues()" readonly></td>
<td><input type="text" class="form-control" id="harga_beli_2" name="harga_beli[]" value="<?php $a=set_value('harga_beli[0]'); echo $a;?>" onKeyUp="getValues()" readonly></td>
<td><input type="text" class="form-control" id="barcode_3" name="barcode[]" value="<?php echo $detail->barcode;?>"></td>
<td><input type="text" class="form-control" id="barang_nama_3" name="barang_nama[]" value="<?php echo $detail->barang_nama;?>" onKeyUp="getValues()" readonly></td>
<td><input type="text" class="form-control" id="harga_beli_3" name="harga_beli[]" value="<?php echo $detail->harga_beli;?>" onKeyUp="getValues()" readonly></td>
我希望这个问题能够得到解决。非常感谢您的回复。
最佳答案
就像 Zerfiryn 提到的:“你不能对 html 元素使用相同的 id。jQuery 只会获取第一个元素”
解决方案:您可以在 html 元素上多次使用同一个类。不要调用 ajax 中的 id,而是调用 form-control
类。因此,将 $("#barcode")
替换为 $(".form-control")
写答案因为我无法发表评论-.-
关于javascript - ajax代码不将数据从表中取出到第二行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41375158/
我有这样的数据。 (a,b,c,d) (g,b,v,n) (n,h,l,o) (,,,) (,,,) (,,,) (,,,) 我想取出空袋子。 所需的输出 (a,b,c,d) (g,b,v,n) (n
我是编程新手,我有一堆 CSV 文件,每个文件大约有 50 到 60 行。在未指定数量的行之后,第二列中有一个名为“NAME”的字符串。我想获取“NAME”之后第二列中的所有内容并将其打印到文本文件中
有没有办法在 linq 中删除以下代码中的 foreach 并产生相同的输出? DropDownList ddl = new DropDownList(); foreach (Data
注意-可以使用UIViewControllerAnimatedTransitioning https://developer.apple.com/library/ios/documentation/u
因此,我开始使用 Swift 为网站构建应用程序。主要目标是拥有一个可以接收通知(来自网站的 JSON)并可以显示网站所有功能的 iOS 应用程序。所以我可以从应用程序登录并注册到我的数据库,但问题是
我希望直接使用 ALAssetsLibrary 和 ALAsset 以 NSData 对象的形式提取图像。 使用 NSURL,我按以下方式取出图像。 NSURL *referenceURL =newU
我是一名优秀的程序员,十分优秀!