简体   繁体   English

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

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

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. 我认为这是在JSF中使用javascript代码的正确方法。 Should I use the <script> tag of html instead? 我应该使用html的<script>标签吗?

Thanks! 谢谢!

That's not the intend purpose of the outputScript tag. 这不是outputScript标记的目的。 It just renders an HTML script tag while resolving the location of the javascript file that's specified in its name attribute. 它只是在解析在其name属性中指定的javascript文件的位置时呈现HTML script标记。

If you need to inline javascript, just enclose it in the <script> tag directly. 如果您需要内联javascript,只需将其直接包含在<script>标记中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM