javascript - 避免/禁用自动跳转到输入字段

标签 javascript html primefaces

我有一个关于 html 输入标签或 primefaces p:input 的问题。 为什么光标总是自动跳转到输入字段。我的页面高度很高,因此您需要向下滚动。输入字段位于页面末尾,光标自动跳转(加载)到页面末尾进入输入字段。我怎样才能避免这种自动跳转?

<h:form id="form">
    <p:commandButton oncomplete="PF('dlgG').show();" value="Open"
        id="button" update="dialog" partialSubmit="true" />
    <p:dialog appendToBody="true" appendTo="@(body)" modal="true"
        id="dialog" resizable="false" closeOnEscape="true" widgetVar="dlgG"
        showEffect="drop" hideEffect="drop">

        <div
            style="width: 90%; height: 100px; background: black; margin-bottom: 1000px;color:red;" id="demo"></div>

        <p:inputTextarea autoResize="true" rows="3" cols="100"
            value="#{auftragBean.comment}" id="inputBox" />
    </p:dialog>
</h:form>

最佳答案

“为什么”是文档和 showcase问题(又名 RTFM ;-)):

p:dialog 有一个 focus 属性,可以在 page 183 of the 5.3 documentation 上读取。

focus null String Defines which component to apply focus

然后page 184它说:

Focus

Dialog applies focus on first visible input on show by default which is useful for user friendliness however in some cases this is not desirable. Assume the first input is a popup calendar and opening the dialog shows a popup calendar. To customize default focus behavior, use focus attribute.

防止这种情况最有可能通过在顶部添加一个不引用值的虚拟输入并在其 onfocus 属性中给出“blur()”来实现。但您也可以使用 this other stackoverflow post 中的解决方案(使用 onShow 未接受的解决方案)

关于javascript - 避免/禁用自动跳转到输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34945859/

相关文章:

javascript - 附加奇怪的行为

javascript - 在 ReactJs 中动态更新数组列表时出错

javascript - 创建一个新的 DOM 元素,其中包含多个元素并附加到 DOM

java - 如何转换日期?

JSF PrimeFaces - 单击按钮时保存所选表格单元格的值

javascript - primefaces 嵌套的 tabview 和选项卡,无法滚动选项卡

javascript - Arshaw fullcalendar 在月 View 的每个单元格中添加自定义 html

html - Chrome 67.0.3396.87 中视频后面的黑框

Javascript:onclick 函数工作一次然后页面恢复到原始状态

html - 垂直居中内容,未知高度, overflow hidden