如何阻止div标签隐藏在JavaScript中?

时间:2017-08-23 15:07:07

标签: javascript jquery html jsp

我有一个div,其中包含名称和电子邮件地址的文本字段。如果验证通过,此div消失,但如果电子邮件地址无效,我想显示消息而不让div消失。对于名称验证我使用JS但是对于电子邮件地址我正在调用服务。

JSP

<form name="resendEsignatureFormId" id="resendEsignatureFormId" action="myStruts2Action "method="POST"/>

<div id="Signers" style="display: none;">
        <s:iterator value="intgDetails.custDetails.signers" var="signerslist">
            <div class="sectionHeaderLine"></div>
            <div class="sectionHeader">Signer #<%=ct%></div>

            <div id="display" class="fieldLabelBold" style="color:red"> 
                <c:if test="${emailValidationMessage != null}">
                    <div class="fieldLabelBold" style="color:red">${emailValidationMessage}</div>
                </c:if>
            </div>

            <table width=100%>                                              
                <tr align="left">
                    <td align="left">
                        <s:textfield name="nameId" id="nameId" label="Name" cssClass="dataFieldCell3" value="%{#signerslist.name}" />
                    </td>
                </tr>
                <tr align="left">
                    <td align="left">
                        <s:textfield name="emailId" id="emailId" label="Email" cssClass="dataFieldCell3" value="%{#signerslist.email}" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <s:textfield name="recipientId" id="recipientId" style="display: none;" value="%{#signerslist.recipientId}" />
                    </td>
                </tr>
                <%
                    ct++;
                %>
            </table>
        </s:iterator>

        <table width=100%>
            <tr>
                <td class="esignNavigation">            
                    <a href="#x" onclick ="return validateEmailAddress()"><span>Confirm</span></a>
                    <a href="#x" onclick="hideSigners()"><span>Cancel</span></a>
                </td>
            </tr>
        </table>
    </div>

JS

function showSigners() {
    $(Signers).show();
}

function hideSigners() {
    if (true == $(Signers).is(':visible')) {
        $(Signers).hide();
    }
} 

function validateEmailAddress() {       
    if( document.getElementById( 'nameId' ).value == "" ) {
        document.getElementById( 'display' ).innerHTML ='Please provide name';
        return false;
    }   
    document.getElementById( 'resendEsignatureFormId' ).submit();
}   

我想通过在函数中检查变量emailValidationMessage的null条件,我可以重新显示div标签,但它不起作用。

function validateEmailAddress() {       
    if( document.getElementById( 'nameId' ).value == "" ) {
        document.getElementById( 'display' ).innerHTML ='Please provide name';
        return false;

    } if( '${emailValidationMessage}' != null ) {
        $(Signers).show();
    }   
    document.getElementById( 'resendEsignatureFormId' ).submit();
} 

0 个答案:

没有答案