简体   繁体   English

如何在弹出窗口中的提交按钮上设置默认焦点 window

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

please help me someone,,,,请帮助我的人,,,,

i write some code to get the popup window using the following code.我使用以下代码编写了一些代码来获取弹出窗口 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>

in this am using the id of the div to populate the popup,like this i have write some other popup code with different ids.在这里我使用 div 的 id 来填充弹出窗口,就像这样我写了一些其他具有不同 id 的弹出代码。 for this i write the code in window.onload function to get the popup, so, i need to set the default focus on the submit button which i mentioned in the above code.为此,我在 window.onload function 中编写代码来获取弹出窗口,因此,我需要将默认焦点设置在上面代码中提到的提交按钮上。

You can set the focus to the submit button with the use of JavaScript or jQuery:您可以使用 JavaScript 或 jQuery 将焦点设置到提交按钮:

JavaScript: JavaScript:

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

jQuery : jQuery

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

you can use the following to set focus into the button您可以使用以下内容将焦点设置为按钮

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

But this may not work, to fix this I have done something like this但这可能行不通,为了解决这个问题,我做了这样的事情

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

The best is to set the focus with javascript after getting the element you want with a ref, just.focus() it.最好的方法是在使用 ref just.focus() 获取所需元素后,使用 javascript 设置焦点。

You can use HTML form tag inside your div to set focus on Submit button.您可以在 div 中使用 HTML 表单标签将焦点设置在提交按钮上。 Use your input tags inside form tag, so whenever you are entering User Name or Password Submit button is always focussed on press of Enter button.在表单标签内使用您的输入标签,因此每当您输入用户名或密码时,提交按钮始终专注于按下 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