简体   繁体   中英

Javascript/JQuery Return focus to specific element in grid after programmatic click

In Enterprise Portal (essentially sharepoint) we're attempting to automatically fire the "click" of a button whenever a td loses focus, and then return focus to the cell of the table we left. The idea is that we want the user to be able to continuously enter data without having to click that button every time.

The problem is, I don't know how to specify a specific cell within the table to return to, so it just returns to the first cell. I've read in several places that this is either very difficult or impossible without things like SlickGrid. Can anyone help me do this in straight up Javascript/Jquery?

The code I have so far looks like this:

<script>

$jQ(window).load(function refreshSummary() {
    var activeElement;
    $jQ("td").focus(function () {
        activeElement = document.activeElement;
    });
    $jQ("td").focusout(function () {
        var refreshLink = "ctl00_ctl00_m_g_78a9aecd_0fef_4b43_a2ff_45942fe92ea0_ctl01_ctl04_RefreshLink";
        document.getElementById(refreshLink).click();
        document.getelementbyid(activeelement).focus();
    });
});
</script>

Don't you want to just focus back on the element after click on focusout?

$jQ(window).load(function refreshSummary() {
    var activeElement;
    $jQ("td").focus(function () {
        activeElement = document.activeElement;
    });
    $jQ("td").focusout(function () {
        var refreshLink = "ctl00_ctl00_m_g_78a9aecd_0fef_4b43_a2ff_45942fe92ea0_ctl01_ctl04_RefreshLink";

        document.getElementById(refreshLink).click();
        $(this).focus();
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM