Jquery在单击按钮时从输入字段获取this.value

时间:2015-12-29 09:20:24

标签: javascript jquery

当我使用jquery单击按钮时,如何从输入字段中获取值? 下面是我的Jquery代码:

asset_status_list = '';
$.ajax({
  type: "GET",
  url: "<?php echo base_url(); ?>operations/asset_status",
  dataType: "JSON",
  success: function (response) {
      for (i = 0; i < response.length; i++) {
          asset_status_list = '<tr><td >' + response[i].job_card_no + '</td><td >' + response[i].number + '</td><td>' + response[i].type + '</td><td ><input type="text" name="view_more_id" class="view_more_id' + response[i].asset_id + ' btn btn-default" id="view_more_id" value="' + response[i].asset_id + '"/><button id="view_more_link" class="view_more_link' + response[i].asset_id + '"><i class="glyphicon glyphicon-zoom-in "></i>View More</button></td></tr>';
          $('#asset_status_tr').append(asset_status_list);

          $("#asset_status_tr").on("click", ".view_more_link" + response[i].asset_id, function () {
              console.log(response);
              var asset_id = this.value;
             alert(asset_id);

          });
      }

      $('#asset_table_status').DataTable({});
  },
  error: function (response) {

  }
});

我想获取输入字段名称view_more_id的值。

1 个答案:

答案 0 :(得分:0)

这是您正在寻找的答案吗? var asset_id = $(“#view_more_id”)。val();