【发布时间】:2015-05-16 01:22:33
【问题描述】:
我正在尝试让我的 jQuery 代码在我的使用 ui:composition 的 JSF 页面中运行。我尝试了很多不同的方法,包括添加<head> 标签、<h:head> 标签,最终我遇到了this answer,因此尝试使用那里的解决方案,但无济于事。
脚本顶部是alert("ready"),所以我知道脚本已经加载,但到目前为止我还没有让它工作。 jQuery 代码本身运行良好(我已经在 JSFiddle 和普通 HTML 页面上对其进行了测试)。
任何建议都会有所帮助!
我的 jQuery:
$(document).ready(function () {
alert("ready");
...
...
});
这是我的 JSF 页面:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns="http://www.w3.org/1999/xhtml"
template="./_Template.xhtml">
<ui:define name="script"><h:outputScript library="javascript" name="jquery-2.1.3.min.js" target="head" /> </ui:define>
<ui:define name="script"><h:outputScript library="javascript" name="jquery-ui.min.js" target="head"/> </ui:define>
<ui:define name="script"><h:outputScript library="javascript" name="1.js"/> </ui:define>
<ui:define name="top">
<h1>Weather App</h1>
</ui:define>
<ui:define name="left">
<h3>Navigation</h3>
...
</ui:define>
<ui:define name="content">
<form name="search_form" id="searchForm" method="GET" action="search_results.html">
<label for="searchBox">Search</label>
<input type="text" id="searchBox" name="searchString" />
<button name="searchKeyword" id="searchKeyword">Submit</button>
</form>
</ui:define>
</ui:composition>
【问题讨论】: