从输入字段获取动态ID [英] Get a dynamic ID from am input field

查看:87
本文介绍了从输入字段获取动态ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取具有动态ID的input fieldid,但出现错误,无法识别的表达式.下面是我的代码:

I am trying to get the id of an input field which has a dynamic id but I get an error unrecognized expression. Below is my code :

  $("#amount_paid' + data[i].patient_visit_statement_id + '").keyup(function() {
       var amount_owed = $('#amount_owed' + data[i].patient_visit_statement_id + '').val();
       var amount_paid = $('#amount_paid' + data[i].patient_visit_statement_id + '').val();
       alert('Amount owed' + amount_owed + 'Amount paid' + amount_paid + '');
       if (amount_owed < amount_paid) {
           alert('Amount to be paid exceeds amount owed');
       }
   });

从具有每个条目动态ID的ID amount_paid中获取值的最佳方法是什么?

What is the best way to get the value from the id amount_paid which has dynamic id for each entry ?

推荐答案

您可以串联

$("#amount_paid" + data[i].patient_visit_statement_id).keyup(function () {
       var amount_paid =  this.value;
       var amount_owed = $("#" + this.id.replace("amount_paid", "amount_owed")).val();
}):

这篇关于从输入字段获取动态ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆