2022年6月23日 星期四

設定焦點直到成功

考慮有些元件是後來才會動態出現,或一開始被設為禁用之後才動態改為啟用,透過 retry 直到成功設定為止
通常是搭配 vue.js 這類透過資料綁定控制顯示隱藏或禁用的方式需要以這種方式設定焦點

function autofocus(elem, id) {
    setTimeout(function () {
        if (id) elem = document.getElementById(id);
        let isFocused = (document.activeElement === elem)
        if (!isFocused) {
            $(elem).focus();
            autofocus(elem);
        }
    }, 100);
}

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...