2013-02-08 72 views
1

我发现简单的一个很好的例子如何显示弹出附近点击:http://roshanbh.com.np/examples/popup-message/无法获取DIV宽/高

我利用这些我按一下按钮,但我似乎无法得到实际宽度或元素的高度,我不完全知道为什么:

function BindObject(o) 
{ 
    o.click(function(e) 
    { 
     var editor = $(this).find(".object_editor"); 

     console.log(editor); 
     console.log(editor.height()); 
    }); 
} 

这里是被打印到控制台:enter image description here

(仅供参考而已,BindObject被称为在文件准备好了,我我也在使用jqote,不确定它有多相关,它可能是)

$("#QuestContent").html($("#QuestTemplate").jqote(quest_data)); 
$("#QuestContent").find(".object").each(function() { 
    BindObject($(this)); 
}); 

它显然发现元素(由编辑器代表),但我无法确定它的宽度或高度。我知道显示设置为无,但这是因为我不想显示它,直到有人点击一个按钮来显示弹出窗口。任何人有任何想法,为什么它总是空?

这里是CSS:

.object_editor{ 
    position:absolute; 
    z-index:10; 
    width:172px; 
    height:102px; 
    text-align:center; 
    color:#FFFFFF; 
    font: 14px Verdana, Arial, Helvetica, sans-serif; 
    background-color:#000000; 
    display:none; 
} 

编辑:和有关jqote以防万一它的需要:

<!-- Object Template --> 
<script type="text/x-jqote-template" id="ObjectTemplate"> 
    <![CDATA[ 
     <span class="object <%= (this.hidden ? "hiddenType" : "") %>">&nbsp; 
      <input class="objectType" type="hidden" name="<%= this.key[0] %>" value="<%= this.type %>"> 
      <input class="objectEntry" type="hidden" name="<%= this.key[1] %>" value="<%= this.entry %>"> 
      <a data-emptytext="<%= object_types[this.type] %>" data-name="<%= this.key[1] %>" target="_blank" href="<%= (this.entry? whUrl(this.type, this.entry) : "#") %>" class="objectName"><%= this.name %><%= (this.entry?" ("+this.entry+")":"") %></a>&nbsp;<i class="icon-edit editObject"></i> 
      &nbsp; 
      <% if(this.remove) { %> 
       <a href=".object" class="deleteParent"><i class="icon-trash"></i></a> 
      <% } %> 
     </span> 

     <!-- Insert our Editor --> 
     <%=$("#ObjectEditorTemplate").jqote({type: this.type, entry:this.entry}) %> 
    ]]> 
</script> 

<!-- Object Editor Template --> 
<script type="text/x-jqote-template" id="ObjectEditorTemplate"> 
    <![CDATA[ 
     <div class="object_editor">My Editor: <%= this.entry %></div> 
    ]]> 
</script> 
+0

太多添加更多的信息,页面可能有多个类叫做object_editor,但无论这就是为什么我使用.find,所以我不认为这应该很重要 – Geesu 2013-02-08 17:05:14

回答

3

的原因是因为显示设置为无。有关类似问题,请参阅this

+0

我尝试使用可见性:隐藏;相反,但它仍然给我一个null值,当我做editor.width或editor.height – Geesu 2013-02-08 17:02:45

+0

一旦我把它移动到它发现它是正确的,我也需要上述。谢谢! – Geesu 2013-02-08 17:18:56

0

试试这个
$('divID').css('width');
同样的高度

+0

我试过editor.css('width')和它说undefined – Geesu 2013-02-08 17:01:04