您可以将脚本文件保存在WebResources/WebContent文件夹中(任何资源文件夹,但路径必须正确),
用于h:outputScript加载脚本文件:(参考)
如果您使用的是 RichFaces,则放置路径:
添加谷歌 CDN:
参考:xhtml 中的 jQuery
您的场景:使用如下代码。
xmlns:h="http://java.sun.com/jsf/html">
$(document).ready(function(){
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
});
Enter this paragraph.
或者
$(document).ready(function(){
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
});
演示: Live Example1(在正文中添加 google CDN)Live Example2(在标题中添加 google CDN)。