jQuery 遍历和查找文本框
jQuery traversing and finding textboxes
如果我正在循环访问表中的元素 - 比如类"pmtos"的隐藏字段 - 如何获取对表中同一单元格内文本字段(输入(的引用?
jQuery 是:
// Loop through each hidden field, which holds the outstanding amount
$(".pmtos").each(function () {
var os = $(this).val();
//
//find text box in same cell - and populate with some value
//
//
});
感谢您在使其工作时提供的任何指导。
马克
以下是编辑
之前问题的解决方案(根据要求(:
$('#allocate').click(function () {
var recd = parseFloat( $('#pmtRecd').val() );
$('input.pmtallocated').each(function() {
var value = parseFloat( $(this).parent().prev().text() );
this.value = (recd >= value) ? value : recd;
recd = recd - this.value;
if (recd == 0) {
return false;
}
});
});
注意:这不依赖于隐藏的输入。它从第二列中的td
中获取文本。
这是小提琴
回答问题后编辑
可以使用siblings('.pmtallocated')
或prev('.pmtallocated')
来获取输入。使用 siblings()
可能是两者中更好的,因为它不依赖于直接在标记中pmtos
之前出现的pmtallocated
:
$(this).siblings('.pmtallocated').val()
尝试
// Loop through each hidden field, which holds the outstanding amount
$(".pmtos").each(function () {
var os = $(this);
var cell = os.parent(); // gets the parent, i.e. the table cell
var input = cell.find('input')[0];
});
你可以使用$(this).closest('input')
看看这个。 可能适合你。
$(".pmtos").each(function () {
var os = $(this).val();
var input = $(this).closest('td').find('input[type=text]');
});
相关文章:
- GTM每隔5秒在页面上查找文本
- Javascript文本框-查找最低的输入和填充
- 查找已提交的文本区域数
- jquery在元素中查找文本节点,并使用标记进行连接和包装
- 从页面中查找长度为4的文本
- 原型JS查找跨度并替换文本
- jQuery在iFrame Src中查找和替换文本
- 在UIWebView中查找并突出显示带变音符号的阿拉伯语文本
- 正在查找最后一次出现的文本
- 使用 Selenium 在 IE9 浏览器中查找 PDF 文本
- 在其他网站上查找/着色/标记文本
- 单击已连接的可排序项时查找列表文本
- 在td旁边的HTML表中查找td文本
- JQuery 按文本查找 LI,按类查找 UL
- 根据文本查找数组中的项
- 如何避免/跳过CKEDITOR 4.0中隐藏/未显示内容中的文本查找
- 如何根据文本查找HTML元素,然后分配ID
- 使用jquery通过文本查找TH对象(表头),而无需遍历表的所有TH's
- 通过a列中包含的文本查找表的第一行,并选择同一行中的B列
- 如何使用量角器按文本查找和单击表元素