0

我的 aspx 页面中有标签,目前我已将其设计为在 onclick 事件上加载。我正在尝试加载按键事件。按键事件未触发,如果我尝试向下/向上箭头,则选项卡正在导航。任何人都可以请帮忙。

         <%@ Page Title="" Language="C#" MasterPageFile="~/NIT.Master" AutoEventWireup="true" CodeBehind="Initiative.aspx.cs" Inherits="NIT_AMPO.Initiative" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<title>Initiative</title>
<script type="text/jscript" >
    $(function () {
        $("#tabs").tabs().addClass("ui-tabs-vertical ui-helper-clearfix");
    });       
   $(document).ready(function () {
       if ('<%=Session["ProjectID"]%>' != "") {
           $('#Contacts').attr('href', '#ContactsPage');
           $('#Comments').attr('href', '#CommentsPage');
           $('#RiskSummary').attr('href', '#RiskAssessmentSummaryPage');
           $('#RiskAssessment').attr('href', '#tabs-3');
           $('#Approvals').attr('href', '#tabs-3');
           $('#Task').attr('href', '#tabs-3');
           $('#Documents').attr('href', '#tabs-3');
           $('#PostLaunch').attr('href', '#tabs-3');
           $('#LinkedInititatives').attr('href', '#tabs-3');
       }
       else {
           $('#Contacts').prop('disabled', true); ;
           $('#Comments').prop('disabled', true);
           $('#RiskSummary').prop('disabled', true);
           $('#RiskAssessment').prop('disabled', true);
           $('#Approvals').prop('disabled', true);
           $('#Task').prop('disabled', true);
           $('#Documents').prop('disabled', true);
           $('#PostLaunch').prop('disabled', true);
           $('#LinkedInititatives').prop('disabled', true);
       }
   });
</script>

<script type="text/javascript">
    function loadIframe(iframeName, url) {
        var $iframe = $('#' + iframeName);
        if ($iframe.length) {
            $iframe.attr('src', url);
            return false;
        }
        return true;
    }
    function refreshPage() {
        //document.getElementById("ifrm").contentWindow.location.reload(true);
        document.getElementById("ifrm").contentWindow.location.href = document.getElementById("ifrm").contentWindow.location.href
    }
    function iframeLoaded() {
        var iFrameID = document.getElementById('ifrm');
        if (iFrameID) {
            iFrameID.height = "";
            var height = iFrameID.contentWindow.document.body.scrollHeight
            if (height < 600) {
                iFrameID.height = "600px";
            }
            else {
                iFrameID.height = height + "px";
            }
        }
    }
    function iframeBlur() {
        window.focus();
    }

    $(function () {
        $('a:first').focus
        var id = $('a:first').focus();
    });

    $(document).on('keydown', function (e) {
        if (e.which == 40) {
            id = $("*:focus");
            id.parents('li').next().find('a').focus();
        }
        else if (e.which == 38) {
            id = $("*:focus");
            id.parents('li').prev().find('a').focus();

        }
    });
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div id="tabs">
    <ul>    
        <li><a id="Main" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'Main.aspx')">Main</a></li>
        <li><a id="Contacts"  href="#iframeInitiative" onclick="return loadIframe( 'ifrm', 'Contacts.aspx')" onfocus="return loadIframe( 'ifrm', 'Contacts.aspx')">Contacts</a></li>
        <li><a id="Comments" href="#iframeInitiative" onclick="return loadIframe( 'ifrm', 'Comments.aspx')" onfocus="return loadIframe( 'ifrm', 'Comments.aspx')">Comments</a></li>
        <li><a id="RiskSummary" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'RiskAssessmentSummary.aspx')" onfocus="return loadIframe( 'ifrm', 'RiskAssessmentSummary.aspx')">Risk Assessment Summary</a></li>
        <li><a id="RiskAssessment" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'RiskAssessment.aspx')">Risk Assessment</a></li>
        <li><a id="Approvals" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'Approvals.aspx')">Approvals</a></li>
        <li><a id="Task" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'ImpactTaskSummary.aspx')">Impact/Task Summary</a></li>
        <li><a id="Documents" href="#iframeInitiative" onclick="return loadIframe('ifrm', 'Documents.aspx')">Documents</a></li>
        <li><a id="PostLaunch" href="#iframeInitiative"  onclick="return loadIframe('ifrm', 'PostLaunch.aspx')">Post Launch</a></li>
        <li><a id="LinkedInititatives" href="#tabs-3">Linked Initiatives</a></li>
    </ul>
    <div id="tabs-3">      
            <div id="left">
                <img id="Logo" src="Images/Website_Page_Under_Construction.jpg" alt="AmEx Logo" height="200" width="200" />
            </div>
        </div>
        <div id="iframeInitiative">
            <iframe name="ifrm" id="ifrm" src="Main.aspx" frameborder="0" width="900px" onload="iframeLoaded()" >
            </iframe>
        </div>
</div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadWindowManager ID="ParentRadWindowManager1" runat="server" EnableShadow="true" Behaviors="Close"
    Style="z-index: 7000">
    <Windows>
        <telerik:RadWindow ID="RiskQuestionnaireDialog" runat="server" ReloadOnShow="true" VisibleStatusbar="false"
            ShowContentDuringLoad="false" Modal="true" BorderStyle="None" Height="560" Width="1000" OnClientClose="refreshPage">
        </telerik:RadWindow>
        <telerik:RadWindow ID="ImpactDetailsDialog" runat="server" ReloadOnShow="true" Height="540" Width="700" OnClientClose="refreshPage"
            ShowContentDuringLoad="false" Modal="true" BorderStyle="None" VisibleStatusbar="false">
        </telerik:RadWindow>
        <telerik:RadWindow ID="SendMailDialog" runat="server" ReloadOnShow="true" Height="460" Width="800" VisibleStatusbar="false"
            ShowContentDuringLoad="false" Modal="true" BorderStyle="None">
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>

4

1 回答 1

0

尝试使用 onfocus而不是onkeypress

像这样

<li><a id="Contacts"  href="#iframeInitiative" onclick="return loadIframe( 'ifrm', 'Contacts.aspx')" onfocus="return loadIframe( 'ifrm', 'Contacts.aspx')">Contacts</a></li>

添加此代码

代码

  $(function(){
    $('a:first').focus
    var id=$('a:first').focus();
});
$(document).on('keydown',function(e)
   {
       if(e.which==40)
       {
          id=$("*:focus");
          id.parents('li').next().find('a').focus();
       }
       else if(e.which==38)
       {
           id=$("*:focus");
           id.parents('li').prev().find('a').focus();

       }
 });

工作演示

于 2013-09-24T09:25:47.770 回答