我有一個關於通過框順序在名稱屬性中更改輸入號碼的問題。當我在第一個框中更改輸入名稱時,第二個帶有無線電輸入的框會丟失選中的值。更改無線電輸入名稱 - 消失無線電選中
$('.container').find('.box').each(function (idx) {
$(this).find('input').each(function() {
let field = $(this);
let fieldName = field.attr('name');
let mIndex = 0;
if (fieldName.length !== 0) {
field.attr('name', fieldName.replace(
/\[\d+]/g,
function (match, pos, original) {
return mIndex++ === 0 ? '[' + idx + ']' : match;
}));
field.attr('id', field.attr('name').replace(/[\[\]]/g, '#').replace(/\#+/g, '-').replace(/[-]+$/g, ''));
field.closest('.field').children('label').attr('for', field.attr('id'))
}
});
這裏是我的代碼示例:https://jsfiddle.net/pbLkabhe/
我的問題是如何解決的Javascript代碼保持無線電輸入檢查後改變輸入名稱值。
我沒有看到你的形式的任何故障。 –
第二個箱子不顯示輸入收音機檢查選項(http://prntscr.com/fl5794) – Matt