我发现简单的一个很好的例子如何显示弹出附近点击: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());
});
}
这里是被打印到控制台:
(仅供参考而已,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" : "") %>">
<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> <i class="icon-edit editObject"></i>
<% 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>
太多添加更多的信息,页面可能有多个类叫做object_editor,但无论这就是为什么我使用.find,所以我不认为这应该很重要 – Geesu 2013-02-08 17:05:14