简体   繁体   English

如何从

[英]How to call a javascript function from a <c:if block

I want to call a javascript function when flow enters into <c:if> block. 当流进入<c:if>块时,我想调用javascript函数。

For example, I have below code: 例如,我有以下代码:

<c:if test="${!empty errorMessage && !(fn:contains(errorMessage, 'generic'))}">
    <span> errorError occured<br />
    </span>
</c:if>

I need to invoke a JS function only when this <c:if> is true. 仅当此<c:if>为true时,才需要调用JS函数。

Please suggest how to achieve this. 请建议如何实现这一目标。

You can include the <script> tag within the <c:if> block, something like this: 您可以在<c:if>块中包含<script>标记,如下所示:

<c:if test="${!empty errorMessage && !(fn:contains(errorMessage, 'generic'))}">
    <span>
        errorError occured<br />
    </span>
    <script>
        alert("Calling my function ...");
        myFunction(); // this is a call to your function which must be defined in the <head> section or another JS file.
    </script>
</c:if>

Hope this helps. 希望这可以帮助。

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

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