HTML代码如下:
<div id="input2" class="clonedInput">
<div class="col-sm-3 text_flied">
<div class="col-sm-4 no-padding">
<input type="" class="bwidth" value="" placeholder="300" name="fr_width[1]">
</div>
<div class="col-sm-1 text_middle no-padding">
<p>X</p>
</div>
<div class="col-sm-4 no-padding">
<input type="" class=" bheight" value="" placeholder="300" name="fr_height[1]">
</div>
</div>
</div>
我想更新输入字段fr_width[1]
的值。此部分动态创建为 fr_width[2]
、fr_width[3]
等。
为了更新该值,我使用了以下代码,但它不起作用。我也尝试了 children()
选项。
$("#input2").siblings(".col-sm-4 input").val('123');
$("#input2").closest(".bwidth").val('123');
这两种方法都不起作用。
最佳答案
尝试 DEMO :-
$("#input2").find(".text_flied").find(".bwidth").val('123');
或者
$("#input2").children(".text_flied").find(".bwidth").val('123');
或者
$("#input2").find(".bwidth").val('123');
或者
最短路线
$("#input2 .bwidth").val('123');
1)- closest
仅适用于祖先或选择器本身。
2)- siblings
仅适用于相同的层次结构节点。
您可以通过多种方式找到所需的选择器
并为其设置值
。
谢谢!
关于javascript - 获取子输入元素值更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26234849/