简体   繁体   English

调用setAnchor()之后,div元素仍会占用空间(仅适用于IE)

[英]After call to setAnchor(), div element still takes up space (IE only)

i have a html of this format. 我有这种格式的HTML。

<html>
<head>
...
</head>
<body>
<label id='view' onClick="ShowMe()">show my name</label>
<img src="home.jpg" width="800px" height="600px"/>
<div id='name' style="display:none;height:200px">Your Name is DARSHAN</div>
</body>
</html>

and in javascript i have this function 在JavaScript中我有这个功能

ShowMe()
{
var nameDiv=Ext.get('name');
var viewDiv=Ext.get('view');
nameDiv.setStyle('display','block');
nameDiv.anchorTo(viewDiv,"tr-br?");

}

this thing works fine in all browsers but in IE,When i Click on 'Show My name' label,its displays the 'name' tag near the show my name but also a vertical space is taken up by 'name' Div tag and a scroll bar appears. 这个东西在所有浏览器中都可以正常工作,但是在IE中,当我单击“显示我的名字”标签时,它会在“显示我的名字”旁边显示“名称”标签,但“名称” Div标签和滚动条出现。 How to get rid of it? 如何摆脱它?

How can this work? 这怎么工作? There are lots of errors in this code: 此代码中有很多错误:

There should be a semicolon in your style attribute value, not a comma : 您的样式属性值中应该有一个分号 ,而不是逗号

<div id='name' style="display:none;height:200px">

There is a typo - display is called dispaly : 有一个错字- display称为dispaly

nameDiv.setStyle('display','block');

Also, what are the setStyle and anchorTo functions? 另外,setStyle和anchorTo函数是什么? What library are they from? 他们来自哪个图书馆? Did you write it yourself? 你自己写的吗? Please provide some more information. 请提供更多信息。

EDIT: Thank you PPvG for adding tag extjs 编辑:谢谢PPvG添加标签extjs

Please provide snippets of the actual working/faulty code (copy and paste) instead of manually writing new code. 请提供实际工作/错误代码的片段(复制和粘贴),而不是手动编写新代码。

The inline style on are divided by a "," 内联样式用“,”除

That's invalid, CSS rules have to end with a semicolon ";" 这是无效的,CSS规则必须以分号“;”结尾

IE is pretty picky when it comes to valid html/css IE对有效的html / css相当挑剔

After discussing it with one of the experts at office i got to know this. 与办公室的一位专家讨论之后,我知道了这一点。

when you define Div at one place and anchorTo somewhere else this problem might come. 当您在某个地方定义Div并将锚定到其他地方时,可能会出现此问题。 how the anchor tag works is it will take the coordinates of the div to which we r anchoring and define the top and left of the new tag accordingly. 锚标签的工作方式是获取锚定的div的坐标,并相应地定义新标签的顶部和左侧。 So we need to make sure that we have defined 'poistion' attribute value to 'absolute'. 因此,我们需要确保已将“ poistion”属性值定义为“ absolute”。

So to my problem solution was adding 所以我的问题解决方案是添加

<div id='name' style="display:none;height:200px;position:absolute">Your Name is DARSHAN</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM