2013-02-08 34 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