我有一组动态构建并添加到页面的输入框。我可以控制放在元素上的ID,但它被一堆垃圾包裹着。例如,我为其指定了clientTest
的ID,它将呈现j_id0:j_id2:theForm:clientTest_mod
的ID。总共有7个输入框包含此Id,但包含不同的结尾。 ID的第一部分也是动态的,所以我不能硬编码。
一个例子,
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_lkid" id="j_id0:j_id2:theForm:clientTest_lkid" value="000000000000000">
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_lkold" id="j_id0:j_id2:theForm:clientTest_lkold" value="null">
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_lktp" id="j_id0:j_id2:theForm:clientTest_lktp" value="001">
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_lspf" id="j_id0:j_id2:theForm:clientTest_lspf" value="0">
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_lspfsub" id="j_id0:j_id2:theForm:clientTest_lspfsub" value="0">
<input type="hidden" name="j_id0:j_id2:theForm:clientTest_mod" id="j_id0:j_id2:theForm:clientTest_mod" value="0">
如何搜索并找到我想要定位的输入框?
答案 0 :(得分:1)
延伸@Michael Chaney
// select the collection
var inputs = $("input[id*='theForm']");
// loop through each element.
$("input[id*='theForm']").each(function(ind, ele){
$("#textPlace").append("<li>"+ $(ele).attr("id")+"</li>");
});