简体   繁体   English

如果条件允许,如何在jstl中使用javascript函数

[英]How to use javascript function in jstl if condition

This is my javascript function:这是我的 javascript 函数:

function isEmpty(field){
    if( document.getElementsByName(field).value === '' )
        return true;
    return false;
}

How to use my javascript function in jstl here:如何在 jstl 中使用我的 javascript 函数:

<c:choose>
    <c:when test ="isEmpty(firstName)">
        <span class="red">please-fill-required-fields</span>
    </c:when>
    <c:otherwise>
        <span class="red"> </span>
    </c:otherwise>
</c:choose>

Jstl codes execute on server side and javascript functions execute after rendering the page by server! Jstl 代码在服务器端执行,javascript 函数在服务器渲染页面后执行! So, you can't use javascript inside jstl code.因此,您不能在 jstl 代码中使用 javascript。 Instead, you should use jstl(not javascript) for checking null value.相反,您应该使用 jstl(而不是 javascript)来检查空值。

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

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