我想在頁面加載後執行JavaScript函數。目前我有一個commandButton,一切正常。然而,如果用戶不應該按下按鈕,它會更舒服。如何在頁面加載後執行JavaScript?
我試過f:event,但是我沒有監聽器,我只有JavaScript函數。此外,身體負荷不適合我,因爲我只使用高級別組件。
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pm="http://primefaces.org/mobile" contentType="text/html">
<ui:composition template="/resources/master.xhtml">
<ui:define name="content">
<pm:content>
<h:inputHidden id="address" value="#{pathFinderBean.address}" />
<div id="map" style="width: 100%; height: 285px;"></div>
<p:commandButton type="button" value="Route" onclick="PathFinder.findAndGo()"/>
<div id="route"></div>
</pm:content>
</ui:define>
</ui:composition>
JavaScript函數PathFinder.findAndGo在我master.xhtml
你願意想這樣做的準備,而不是onload事件? –
如果您的腳本在頭部並且按鈕位於頁面中,則該腳本將始終在元素出現之前加載。但是,如果腳本需要某些元素在頁面中,並且用戶可以在加載之前單擊該按鈕,則可能會禁用該按鈕(或採取其他操作)直到它們可用。 – RobG
使用remoteCommand且autorun爲true。 – meyquel