我们有以下形式:
<form>
...
<table width="100%" cellspacing="0" class="datagrid_ppal">
<tbody>
<tr>
<th scope="row">Area 1 <input name="config_line" type="hidden" value="0,5,50" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
...
</tr>
</tbody>
</table width="100%" cellspacing="0" class="datagrid_ppal">
...
<form>
我们需要的是从隐藏的输入值中获取第一个、第二个或第三个。我们已经尝试过了,但没有成功:
var value = $('th').children('input:hidden').val();
有人可以帮助我们吗?我们将非常感激。
最佳答案
隐藏字段的值不是数组,而只是字符串:“0,5,50”。
要使用 jQuery 检索该值,请使用:
$('input[name=config_line]').val()
要将该字符串拆分为数组,请使用 split() 方法。
合并:
var firstValue = $('input[name=config_line]').val().split(",")[0]; // etc...
关于javascript - jQuery:从输入数组获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950631/