使用 <h:outputScript> 在 JSF 中添加 javascript 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8913930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:58:03  来源:igfitidea点击:

Using <h:outputScript> to add javascript code in JSF

javascriptjsfjsf-2

提问by Ben

I'm trying to run some basic javascript code with JSF 2. I'm using the following code to do so:

我正在尝试使用 JSF 2 运行一些基本的 javascript 代码。我正在使用以下代码来执行此操作:

<h:outputScript target="head">
    var props = $.event.props;
</h:outputScript>

Looking at the source of the page I can't find any evidence of this code. I thought that was the correct way to work with javascript code in JSF. Should I use the <script>tag of html instead?

查看页面的来源,我找不到此代码的任何证据。我认为这是在 JSF 中使用 javascript 代码的正确方法。我应该使用<script>html的标签吗?

Thanks!

谢谢!

回答by lsoliveira

That's not the intend purpose of the outputScripttag. It just renders an HTML scripttag while resolving the location of the javascript file that's specified in its nameattribute.

这不是outputScript标签的预期目的。它只是script在解析在其name属性中指定的 javascript 文件的位置时呈现一个 HTML标记。

If you need to inline javascript, just enclose it in the <script>tag directly.

如果您需要内联javascript,只需将其<script>直接包含在标签中即可。