jQuery未在JSF应用程序中运行 [英] jQuery not running in JSF Application
问题描述
在netbeans中,我有 jquery-1.7.2.js 其中存在所有HTML文件。我正在创建JSF 2.0项目。
以下是我的代码
<?xml version ='1.0'encoding ='UTF-8'?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
xmlns:h =http://java.sun.com/jsf/html
xmlns:f =http://java.sun.com/jsf/core
xmlns:t =http://myfaces.apache.org/tomahawk
xmlns:ui = http://java.sun.com/jsf/facelets
>
< h:头>
< title>欢迎使用MySite。< / title>
< / h:头>
< script language =text / javascriptsrc =#{facesContext.externalContext.requestContextPath} /faces/jquery-1.7.2.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
alert('我在这里...');
$(#table tr:last)。after(< ; tr>< td>某些< / td>< td>内容< / td>< / tr>);
});
< / script>
我相信在这段代码中,无论何时加载文档,我都应该有我在这里......
但是我没有收到任何提醒。
另外,当我看到view source&点击 jquery-1.7.2.js
,它被打开。
任何想法为什么我没有获得警觉?
更新1
我接下来的教程提供了 这里 ,仍然没有运气。 :($ / b>
这似乎是一个糟糕的文件位置,我不知道你在哪里把jquery文件放到你的web应用中,但无论如何它应该位于文件夹下的资源文件夹,所以...
添加资源
文件夹下的 WebContent
和内部资源创建 js
文件夹 p>
然后像这样访问文件
< h:outputScript name = js / jquery-1.7.2.jstarget =head/>
I am newbie to jQuery.
In netbeans I have jquery-1.7.2.js where all HTML files are present. I am creating JSF 2.0 project.
Below is the code I have
<?xml version='1.0' encoding='UTF-8' ?>
<!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:t="http://myfaces.apache.org/tomahawk"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>Welcome to MySite.</title>
</h:head>
<script language="text/javascript" src="#{facesContext.externalContext.requestContextPath}/faces/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('I am here...');
$("#table tr:last").after("<tr><td>some</td><td>content</td></tr>");
});
</script>
I believe with this code, whenever document gets loaded, I should have got alert as Hi, I am here...
however I am not getting any alert.
Also, when I see view source & click on jquery-1.7.2.js
, it gets opened.
Any idea why I am not getting alert?
Update 1
I am following tutorial provided here, still no luck. :(
It seems like a bad location of file, I dont where exactly you placed the jquery file in your web app , but anyway It should be located in folder under the resources folder, So...
Add resources
folder under the WebContent
and inside resources create js
folder
then access the files like this
<h:outputScript name="js/jquery-1.7.2.js" target="head" />
这篇关于jQuery未在JSF应用程序中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!