ste*_*fan 18 javascript onload primefaces jsf-2
我想在页面加载后执行JavaScript函数.目前我有一个commandButton,一切正常.然而,如果用户不应该按下按钮会更舒服.
我试过f:event,但是我没有监听器,我只有JavaScript函数.此外,body onload对我不起作用,因为我只使用高级组件.
<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>
Run Code Online (Sandbox Code Playgroud)
JavaScript函数PathFinder.findAndGo在我的master.xhtml中定义
Bhe*_*ung 24
使用JQuery如下:
<script>
jQuery(document).ready(function() {
PathFinder.findAndGo();
});
</script>
Run Code Online (Sandbox Code Playgroud)
更新:
它必须在内<ui:define name="content">
.
当我想在Primefaces中加载页面后执行JS函数时,有两种方法对我有用:
jQuery(document).ready(function () {
jQuery(document).ready(function () {
// twice in document.ready to execute after Primefaces callbacks
PathFinder.findAndGo();
});
});
<p:remoteCommand oncomplete=" PathFinder.findAndGo(); " autoRun="true"/>
归档时间: |
|
查看次数: |
49663 次 |
最近记录: |