显示/隐藏<div>标签不起作用</div>

时间:2011-05-04 15:57:54

标签: javascript ajax

我有一个超链接,应该在onclick事件中逐个调用3个JS函数。

<form name = "bulkcontactfrm" method="POST" action="<%= servletPath %>>
    <div id="saveDiv" layoutAlign="top" style="display:block;"> 
        <table id=""  align="left"  border="0" cellpadding="0" cellspacing="0">
        <tr>
             <td>
            <a href="javascript:void(0);" onclick="isAllowedToResubscribe(document.bulkcontactfrm); manipulateDIV(document.bulkcontactfrm); resubscribeCall(document.bulkcontactfrm);">&#160;Re-Subscribe</zoniac:roundrect>&#160;</a>
            </td>
        </tr>                        
        </table>
    </div>
    <div id="loadingDiv" class="cellWhiteBGFont" layoutAlign="top" style="display: block;"><p><img src="<%=ImageMappingManager.getImageName("imgLoading")%>" name = "b1">&nbsp;&nbsp;<font size='3'><b>Please wait...<b></font></p>
    </div>
</form>

这是JS函数:

// First function validate the data using ajax call
function isAllowedToResubscribe(form) {
    //Client validation takes here 
    processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailValidationDetails',emilIDStr,sourcefromStr);
}

// Second function hide the content in UI and show the Processing image in <DIV> tag
function manipulateDIV(form) {
    hideSaveDiv();
    showLoadingDiv();
}

function hideSaveDiv() {

    //hide the Re-Subscribe hyperlink 
    document.getElementById('saveDiv').style.display='none';
}
function showLoadingDiv() {
    //show the Processing image 
    document.getElementById('loadingDiv').style.display='block';
}

// Third function is for form submit using ajax call
function resubscribeCall(form) {
    //processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailDetails',emilIDStr,sourcefromStr);
}

单击超链接验证函数调用并获得成功后,将出现确认消息,在构造上单击“确定”。但<DIV>标记未被隐藏,因此进度图像未加载。

1 个答案:

答案 0 :(得分:0)

这里的代码有点混乱,所以很难说出问题出在哪里,以及你在这里粘贴的内容是否正是你正在使用的内容。但有一种可能性是它没有正确定位div,因为你在"标记中缺少form标记:

<form name = "bulkcontactfrm" method="POST" action="<%= servletPath %>>

应该是:

<form name="bulkcontactfrm" method="POST" action="<%= servletPath %>">

快速测试似乎表明缺少"会使DOM充分混乱,导致document.getElementById()无法正常工作。比较http://jsfiddle.net/nrabinowitz/n9S33/2/http://jsfiddle.net/nrabinowitz/n9S33/3/以查看此操作。