jQuery从列中的隐藏输入中获取值
jQuery get value from hidden input in column
我得到了以下HTML表。。。
<table>
<thead>
<tr>
<th>Nr.</th>
<th>Name</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Laura</td>
<td><input type="hidden" value="1"><a href="#" class="info">Info</a></td>
</tr>
<tr>
<td>2</td>
<td>Sabrina</td>
<td><input type="hidden" value="2"><a href="#" class="info">Info</a></td>
</tr>
</tbody>
</table>
单击链接时,如何使用jQuery获取隐藏输入字段的值?
$(".info").click(function() {
// Here I need to find out the value...
});
以下是您的操作方法:
$(".info").click(function(e) {
//just in case, will be useful if your href is anything other than #
e.preventDefault();
alert($(this).prev('input[type="hidden"]').val());
});
prev
方法将搜索上一个元素,即input[hidden]
所在的位置。
以及<a/>
标签中的href
,而不是hre
。
您也可以使用属性<a href="#" data-hidden="1" class="info">
不需要使用隐藏字段
$(".info").click(function(e) {
e.preventDefault();
alert($(this).data('hidden')); // or $(this).attr('data-hidden');
});
相关文章:
- 从MySQL数据库中获取输入数据需要两次页面刷新
- 输入字段将't获取更新的值
- 如何从客户端的数组中获取用户输入和返回值
- 在数据库中循环值时,为输入框获取唯一值
- Javascript获取具有不同id的文件数's来自没有多个属性的文件输入元素
- 如何使用html/html5中的用户输入获取完整的地理位置详细信息
- 使用 D3 中用户的输入获取值
- 我如何使用javascript并根据提供的输入获取JSON数据
- 提前输入获取远程数据问题
- 根据递归ul中的输入获取一个表单的序列化数组
- 正在尝试根据用户输入获取总额
- Emberjs:从输入获取数据
- 从任意数量的输入获取JavaScript对象
- 在鼠标输入获取下拉元素的焦点
- 如何使用javascript或jquery为新表单输入获取更新的json文件
- 通过用户输入获取变量
- 我如何从html输入获取属性值
- 另一个选项更直接地从td中的输入获取title属性
- 从命令行输入获取完整的iframe url,并从python变量解析为HTML
- AngularJS FORMs:根据前面的输入获取第二个SELECT BOX的Items