This commit is contained in:
ken 2026-09-03 12:18:32 +08:00
parent 6471d425a8
commit 201020ddb9
1 changed files with 33 additions and 0 deletions

View File

@ -3483,5 +3483,38 @@ setTimeout(function() {
}
});
}, 700);
$(function() {
function fixLabelForMismatch() {
setTimeout(function() {
// ✅ 找所有 label檢查 for 屬性是否有對應的 input id
$('label[for]').each(function() {
var $label = $(this);
var forAttr = $label.attr('for');
// ✅ 已有正確對應則跳過
if ($('#' + forAttr).length > 0) return;
// ✅ 找同一個 control-group 裡的 input/select/textarea
var $group = $label.closest('.control-group');
if ($group.length === 0) return;
var $input = $group.find('input:not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]), select, textarea').first();
if ($input.length === 0) return;
var inputId = $input.attr('id');
if (!inputId) {
// ✅ input 沒有 id補上一個和 for 一致的 id
$input.attr('id', forAttr);
} else {
// ✅ input 有 id 但和 for 不一致,把 label for 改成 input id
$label.attr('for', inputId);
}
});
}, 500);
}
fixLabelForMismatch();
});
}(jQuery, window));