我有以下jQuery,确实找到ASP.NET服务器控件(通过在块内放置alert()进行测试),但它不会使用.next()在DOM中设置下一个DIV的高度。但是,如果我使用直JS来做同样的事情,直接调用DIV它可以正常工作。为什么在我的jQuery中无法使用下一个'div'?
我想要做的不是使用DIV的硬编码ID,以防万一它改变,而是走动DOM动态地到达元素并设置高度。
所以1:
<div id="WebViewer" style="height:100%;width:100%;margin-right: 0px">
<input name="WebViewerReportReceipt" type="hidden"/>
<input name="WebViewerViewerType" type="hidden"/>
<DIV id="WebViewer_controlDiv">
<iframe src="295769102_1619997395_16141400_2120403583/CacheItem" style="width:100%;height:100%;"></iframe>
</DIV>
</div>
下一页非工作jQuery的,我认为应该工作:什么我试图操纵HTML源
//Using the 'DIV' that is created by the viewer (at runtime), resize it dynamically to fit the window
var myHeight = $(window).height();
if ($('#<%=WebViewer.ClientID %>') != null) {
$('#<%=WebViewer.ClientID %>').next('div').height(myHeight - 10);
}
最后是JS那确实工作,但我不希望通过硬编码ID访问该DIV,而是使用jQuery代替:
var myHeight = $(window).height();
//Using the 'DIV' that is created by the viewer (at runtime), resize it dynamically to fit the window
if (document.getElementById('WebViewer_controlDiv') != null) {
document.getElementById('WebViewer_controlDiv').style.height = myHeight - 10;
}
关于为什么在jQuery中走DOM以获取'next'div并设置其高度的任何想法都不起作用?
谢谢!