如何在每个循环的jquery中获取隐藏字段的值?

时间:2018-08-29 12:08:16

标签: javascript jquery

我正在遍历Div循环,在那个div中,将编码数组分配为隐藏字段的值,并希望在每个循环中获取该隐藏字段的值,但无法定义

var port_ofAir = null; $(".sublocation_div").find('.sublocation').each(function(index,value1){
    port_ofAir = $(this).find(".port_arr").value;

  });
  console.log(port_ofAir)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" name="arr_port" class="port_arr" id="arr-port" value="[{"id":34,"client_id":"2"}]">

我想在jquery函数中获取该数组

请提出任何建议

2 个答案:

答案 0 :(得分:0)

在jQuery中,您需要使用.val()而不是.value

port_ofAir = $(this).find(".port_arr").val();

答案 1 :(得分:0)

尝试以下操作:您需要使用.val(),而不是value。另外,您可以使用input[type=hidden]

为隐藏字段放置特定的jQuery选择器
$(".sublocation_div").find('.sublocation').each(function(index,value1){
    var port_ofAir = $(this).find("input[type=hidden].port_arr").val();
 }
相关问题