This commit is contained in:
parent
6471d425a8
commit
201020ddb9
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue