use*_*566 6 javascript each jquery
$("[name=form_1]").each(function(){
alert("i in else"+i);
$('.eform_text').each(function() {
});
});
Run Code Online (Sandbox Code Playgroud)
这个循环会迭代所有只有form1的eform_text类的元素.或者它会遍历所有拥有该类的元素吗?
确切的jsp代码如下:
<c:when test="${eformDetails.controlType==1}">
<input id="textBox_${eformDetails.id}_${eformDetails.required}_${i}" class="eformDetail eform_text" type="text" value="" name="form_${i}" onblur="validateEformInputs(${i-1})"></input>
</c:when>
我有每次变化的形式.对于每个表格,我需要获得所有的文本框.目前在你的帮助后我的javascript是屁股跟随:
$("[name = form _"+ i +"]").each(function(i){alert("i in else"+ i);
$('.eform_text', this).each(function() {
textboxId = $(this).attr("id");
Run Code Online (Sandbox Code Playgroud)
它到达第一个警报,但我无法到达第二个循环.它没有获得具有类eform_text的元素.不知道这里出了什么问题.你能帮忙吗?
T.J*_*der 11
它将遍历具有该类的所有元素,无论是否在名称为"form_1"的表单内.要仅查看每个表单(我猜你必须有多个名称为"form_1"的表单,尽管这看起来很奇怪),请find在外部循环中使用以限定内部循环:
$("[name=form_1]").each(function(formIndex) {
alert("formIndex in each: " + formIndex);
$(this).find('.eform_text').each(function(textIndex) {
alert("textIndex in each: " + textIndex);
});
});
Run Code Online (Sandbox Code Playgroud)
或者你可以使用第二个参数$(),它提供了工作的上下文:
$("[name=form_1]").each(function(formIndex) {
alert("formIndex in each: " + formIndex);
$('.eform_text', this).each(function(textIndex) {
alert("textIndex in each: " + textIndex);
});
});
Run Code Online (Sandbox Code Playgroud)
要么应该工作.
请注意,正如@Shrikant Sharat在评论中指出的那样(感谢Shrikant!),我假设i原始代码中的内容是要传入的索引each.我已经在上面显示了两个级别的索引(带有描述性名称).
| 归档时间: |
|
| 查看次数: |
12375 次 |
| 最近记录: |