weixin_33713707 2017-03-13 00:11 采纳率: 0%
浏览 25

循环此ajax调用

On my invoice form, users have the ability to click on a button to add as many parts as the want and then the code below automatically fills in the part description and part price.

I tried to loop it but its not working, instead i added multiple scripts for partnumber1, partnumber2, partnumber3 etc.

<script type="text/javascript">

$( "#partstable" ).on( 'blur keyup', "#partnumber" , function() {

searchString=$(this).val();

   var data = 'partnumber='+searchString;

   if(searchString) {
       // ajax call

       $.ajax({
           type: "POST",
           url: "partpricequery.php",
           data: data,

          success: function(html){ 

result = String(html).split("|"),

$("#partdescription").val(result[0]);
$("#partprice").val(result[1]);

showlabel ();

         }
       });    
   }
   return false;
});

</script>

2nd one

<script type="text/javascript">

$( "#partstable" ).on( 'blur keyup', "#partnumber1" , function() {

searchString=$(this).val();

   var data = 'partnumber='+searchString;

   if(searchString) {
       // ajax call

       $.ajax({
           type: "POST",
           url: "partpricequery.php",
           data: data,

          success: function(html){ 

result = String(html).split("|"),

$("#partdescription1").val(result[0]);
$("#partprice1").val(result[1]);


showlabel ();

         }
       });    
   }
   return false;
});

</script>

3rd

<script type="text/javascript">

$( "#partstable" ).on( 'blur keyup', "#partnumber2" , function() {

searchString=$(this).val();

   var data = 'partnumber='+searchString;


   if(searchString) {
       // ajax call

       $.ajax({
           type: "POST",
           url: "partpricequery.php",
           data: data,

          success: function(html){

result = String(html).split("|"),


$("#partdescription2").val(result[0]);
$("#partprice2").val(result[1]);

showlabel ();

         }
       });    
   }
   return false;
});

</script>

This is how i tried to loop it but again its not working

<script type="text/javascript">

var count = 0;
$( "#partstable" ).on( 'blur keyup', "#partnumber"+count , function() {

searchString=$(this).val();

   var data = 'partnumber='+searchString;

   if(searchString) {
       // ajax call

       $.ajax({
           type: "POST",
           url: "partpricequery.php",
           data: data,

          success: function(html){ 

result = String(html).split("|"),

var counter=0;
loop{
$("#partdescription"+counter).val(result[0]);
$("#partprice"+counter).val(result[1]);
counter++;
}

showlabel ();

         }
       });    
   }
   return false;
});

</script>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 房号如何排序,sql或算法
      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题
      • ¥15 无法使用cnssc调取网页数据
      • ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错