如何在jstl条件下使用javascript函数

How to use javascript function in jstl if condition

本文关键字:javascript 函数 条件下 jstl      更新时间:2023-09-26

这是我的javascript函数

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

如何在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代码在服务器端执行,javascript函数在服务器渲染页面后执行!所以,你不能在jstl代码中使用javascript。相反,您应该使用jstl(而不是javascript)来检查空值。