簡體   English   中英

如何在彈出窗口中的提交按鈕上設置默認焦點 window

[英]how to set default focus on the submit button in a popup window

請幫助我的人,,,,

我使用以下代碼編寫了一些代碼來獲取彈出窗口 window。

<div id="EMAIL_CONFIRMATION_PENDING" class="popupContact" style="z-index:10003;">
                <div class="popup_textarea">
                    <h3><h:outputLabel value="#{labelMsgs.emailPendingLabel}"/></h3>
                    <div class="VerifyEmailText">
                        <h:outputLabel value="#{labelMsgs.clickToSendEmail}"/> 
                        <span class="FontItalic"><h:outputLabel value="#{headerBean.emailAddress}."/></span>
                        <br /><br />                         
                    </div>
                    <div  class="SuspendedBoxMsg">
                        <h:outputLabel value="#{labelMsgs.accountSuspend}"/><br />
                        <h3><h:outputLabel value="#{sessionScope.DASHBOARD_EMAIL_EXP_TIME}"/></h3>
                        <h:outputLabel value="#{labelMsgs.unlessYouVerify}"/>
                        <br />                                                        
                    </div>
                    <div>
                        <span class="FontWeight">
                            <h:outputLabel value="#{labelMsgs.spamMailFolder}"/>
                         </span>
                        <a4j:commandLink id="resendLink" styleClass="violet_color_link" value="#{labelMsgs.regSuccSendMail}" onclick="javascript:resendLink(); this.onclick=null;" action="#{headerBean.resendEmail}" />
                    </div>
                    <div class="OkButton">
                        <div class="button_input">                          
                            <a4j:commandButton id="emailConfm" styleClass="image_button" value="#{labelMsgs.okButton}" action="#{accntDashboardBean.popupRefresh}"
                                reRender="frmAccountDashboardMenu:POPUP_PANEL" oncomplete="disablePopup1('EMAIL_CONFIRMATION_PENDING', 'backgroundPopup');popupCall('#{sessionScope.toShowPopupOf}');"/>
                        </div> 
                    </div>
                </div>
            </div>

在這里我使用 div 的 id 來填充彈出窗口,就像這樣我寫了一些其他具有不同 id 的彈出代碼。 為此,我在 window.onload function 中編寫代碼來獲取彈出窗口,因此,我需要將默認焦點設置在上面代碼中提到的提交按鈕上。

您可以使用 JavaScript 或 jQuery 將焦點設置到提交按鈕:

JavaScript:

document.getElementById('emailConfm').focus();

jQuery

$('#emailConfm').focus();

您可以使用以下內容將焦點設置為按鈕

document.getElementById('emailConfm').focus();

但這可能行不通,為了解決這個問題,我做了這樣的事情

setTimeout(function() { document.getElementById('emailConfm').focus(); },100);

最好的方法是在使用 ref just.focus() 獲取所需元素后,使用 javascript 設置焦點。

您可以在 div 中使用 HTML 表單標簽將焦點設置在提交按鈕上。 在表單標簽內使用您的輸入標簽,因此每當您輸入用戶名或密碼時,提交按鈕始終專注於按下 Enter 按鈕。

 <form> <input type="text"/> <input type="password"/> <input type="submit"/> </form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM