当用户单击“评论”按钮时。
<input id="SubmitCommentsToInvoice" type="button" value="Comments" onclick="ShowCommentBox('<%: item.DBId %>', '<%: item.LabourOrPlant %>', '<%: item.ActivityDescription %>')" />
加载文本区域,并带有提交按钮。当用户完成输入数据并单击“提交”时,我希望该框消失。(返回正常屏幕查看)
<div id="dialog" title="Comments" style="display:none;">
<textarea id="BlankBox" type="text" runat="server" rows="7"
maxlength="2000" />
<input id="SubmitComment" type="button" value="Submit"
onclick="SubmitButton()" />
</div>
function SubmitButton() {
var commentBoxData = $('#<%=BlankBox.ClientID%>').val();
WorkItemMgr.CommentBoxForInvoiceUpdates(id, LabouringOrPlanting, commentBoxData, testForSuccess);
}
function testForSuccess(CommentSuccessfullyUpdated)
{
if (CommentSuccessfullyUpdated == "TRUE")
{
//$('#' + IdCommentBox).hide();
// $('#<%=BlankBox.ClientID%>').hide(); just hides comment box need to hide entire thing
$("#dialog").dialog({ modal: true }).hide();
//IN HERE I WOULD LIKE TO HIDE THE DIV (MY ATTEMPTS SEEN ABOVE)
}
else if (CommentSuccessfullyUpdated == "False")
{
showLoadingImage.src = "../Images/X.png";
}
}
我的尝试隐藏了文本区域,但我想再次隐藏整个 div 并返回到屏幕的正常查看(摆脱 modal:true)
最佳答案
我不认为这条线正在做你认为它正在做的事情:
$("#dialog").dialog({ modal: true }).hide();
这告诉对话框插件将#dialog
初始化为新对话框(模式),然后告诉jQuery隐藏整个内容。如果此时#dialog
已经是一个模式对话框,而您只想隐藏它,请尝试以下操作:
$("#dialog").dialog("close");
这告诉对话框插件隐藏(或关闭)现有对话框。
一般来说,如果可能的话,您希望使用插件的 native 功能,而不是尝试对其应用其他功能。在这种特殊情况下,最好告诉 jQuery UI 对话框隐藏自己,而不是尝试使用 jQuery(它不知道对话框插件)来隐藏 div,因为它不知道是否有什么“特殊”之处那个 div (有,另一个插件正在使用它...... jQuery UI 对话框)。
关于javascript - 单击按钮时隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15531381/