我在 Javascript 方面遇到了奇怪的问题,我正在尝试实现系统来更新一些内容,当我按下按钮时,我想隐藏除“MainContent_UpdateProgress”之外的所有内容,但文本区域仍然可见。
asp.net 中的文本区域如下所示:
<textarea runat="server" id="serverOutputTextArea" cols="50" rows="30" name="serverOutputTextArea" visible="false">
Javascript代码:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack())
args.set_cancel(true);
postBackElement = args.get_postBackElement();
if (postBackElement.id == 'MainContent_UpdateAnalysisSystem')
{
$get('MainContent_serverOutputTextArea').style.display = 'none'; //Doesn't work
$get('MainContent_UpdateProgress').style.display = 'block'; //Works
$get('MainContent_ProcessingStatus_Label').style.display = 'none'; //Works
$get('MainContent_ShowDetails_Button').style.display = 'none'; //Works
}
}
问题是,textarea 有什么不同?
最佳答案
您是否查看过浏览器的源代码以了解文本区域的实际 id 是什么?可能您已将其放置在其他某个元素中,并且它继承了更长的 id。
否则,您可以使用以下方式获取 id:<%= serverOutputTextArea.ClientID%>
JavaScript 行将如下所示:
$get('<%= serverOutputTextArea.ClientID %>').style.display = 'none';
关于JavaScript 不会隐藏 asp.net 中的文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11083831/