我的容器中只有几个输入字段,用户可以将这些字段相乘。我需要根据容器更改输入字段的名称。
<div class="stations">
<input type="radio" name="pp[prc][0][station][0][id]">
<input type="radio" name="pp[prc][0][station][1][id]">
</div>
这是我的 HTML 表单。
$(".stations").each(function(sIndex){
//Loop thru all .station
$("input:radio", $(this)).each(function(rIndex){
//Loop thru all radio buttons inside that container and change their names accordingly
$("input:radio", $(this)).attr('name','pp[prc]['+sIndex+'][stations]['+rIndex+'][id]');
});
});
当我这样做时,由于某种原因,当用户重复<div class="station">
时其内容单选按钮的名称不会相应更改。我哪里做错了?
最佳答案
您正在使用 $(selector, context)
并且输入元素不能有子元素,您应该编码:
$(this).attr('name', '...');
关于javascript - 如何处理多个div内的多个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16005971/