如何在JSF 2.0中使用jQuery
我正在学习jQuery。 我想在我的jsf 2.0应用程序中使用jQuery。 就像我有html文件,我正在使用这样的jQuery
The Devil's Dictionary
我只是从jQuery官方网站下载了jquery-1.7.1.js文件,将其包含在我的目录中,然后开始使用jQuery。
我的06.js文件conatin代码是这样的
$(document).ready(function() { $('#letter-a a').click(function(){ /** * The .load() method does all our heavy lifting for us! We specify the target location for * the HTML snippet by using a normal jQuery selector, and then pass the URL of the file to * be loaded as a parameter to the method. Now, when the first link is clicked, the file is * loaded and placed inside . The browser will render the new HTML as * soon as it is inserted, */ $('#dictionary').load('a.html'); return false; }); //end of $('#letter-a a').click() /** * Occasionally, we don't want to retrieve all the JavaScript we will need when the page is * first loaded. We might not know what scripts will be necessary until some user interaction * occurs. We could introduce tags on the fly when they are needed, but a more elegant * way to inject additional code is to have jQuery load the .js file directly. * * Pulling in a script is about as simple as loading an HTML fragment. In this case we use * the $.getScript() function, which, like its siblings, accepts a URL locating the script * file, as shown in the following code snippet: */ $('#letter-c a').click(function(){ $.getScript('js/c.js'); return false; }); //end of $('#letter-c a').click(function()) }); //end of $(document).ready(fn)
这是我的html文件代码段
The Devil's Dictionary
我想问一下,如果我在JSF2.0上创建相同的页面,那么jQuery将以相同的方式工作,或者我必须下载一些插件以在我的JSF 2.0应用程序中使用jQuery? 或者修改我的web.xml中的内容?
谢谢
它的工作方式相同。
ID属性
JSF将表单的ID附加到表单内的所有输入字段。 因此,您需要小心jQuery选择器。 例如,假设您有以下forms:
使用jQuery,你必须将输入引用为: $("#myForm\\:myInput")
构架
一些框架,如PrimeFaces,如果你导入你的jQuery,使用可能无法工作的组件或可能会丢失它们的皮肤:
相反,您应该通过导入使用他们的内置jQuery库:
但是,这个jQuery库包含在冲突模式中,这意味着你不能使用$()
。 因此,您可能需要以下附加设置:
$ = jQuery; // Then you can use it $(document).ready(function() { ... });