我想在页面加载后执行一个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>
在我的master.xhtml中定义了JavaScript函数PathFinder.findAndGo
发布于 2012-01-25 08:27:02
按如下方式使用JQuery:
<script>
jQuery(document).ready(function() {
PathFinder.findAndGo();
});
</script>
更新:
它必须在<ui:define name="content">
中。
发布于 2012-01-25 08:30:01
window.onload = function () {
// code to execute here
}
https://stackoverflow.com/questions/8996316
复制相似问题