您好,我是 JSF 和 jQuery 的新手。 我需要下载任何 jQuery jar 并打包到 war 才能使用吗? 因为在我的代码中我无法调用jquery函数。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/06.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#form\\:name").click(function() {
alert("hii");
});
});
</script>
</h:head>
<h:body>
<h:form id="form">
<h:outputText id="hi" value="hi guys"></h:outputText>
<input id="name" />
</h:form>
</h:body>
</html>
当我单击输出框时,不会弹出此警报。
在我的 pom 中我使用了这个依赖项。
<dependency>
<groupId>com.efsavage.jquery</groupId>
<artifactId>jquery-maven</artifactId>
<version>1.7.2</version>
</dependency>
最佳答案
您可以像在其他 Web 应用程序中一样使用它,jsf 标签也支持 onclick 属性。 请下载我的 jsf-frontend 完全配置的 Web 应用程序(JSF2.2+Primefaces+JQuery)并对其进行测试。 Here is a link, JSF2.2 front end
注意一点:Primefaces 也使用了 Jquery,您可以使用它,也可以跳过并包含您的 jquery。 在我的项目中,您可以找到带有配置的头文件。
这里也是一个很好的例子How to get JSF id via jQuery 祝你好运!
关于javascript - 如何在 JSF 中使用 jQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27344981/