我想創建一個div,只有當它高於一定的高度後,才能滾動,並附加文本。我使用jquery檢查高度,並且每次都返回零。有什麼建議麼?獲取JQuery .height()追加到另一個div後返回0
HelpOverlay.prototype.buildContent = function(helpMappings){
this.content = $('<div class="content"></div>');
var table = $('<table></table>');
table.append($('<tr><td class="key"><h3>Key</h3></td><td class="command"><h3>Command</h3></td></tr>'));
this.content.append(table);
for (var whichCategory = 0; whichCategory < helpMappings.categories.length; whichCategory++) {
var category = helpMappings.categories[whichCategory];
var categoryDiv = $('<div class="category">' + category.category + '</div>');
this.content.append(categoryDiv);
var categoryTable = $('<table></table>');
for (var whichMapping = 0; whichMapping < category.mappings.length; whichMapping++) {
var mappings = category.mappings[whichMapping];
var row = $('<tr></tr>');
var keyCell = $('<td class="key">' + mappings.key + '</td>');
var commandCell = $('<td class="command">' + mappings.command + '</td>');
row.append(keyCell);
row.append(commandCell);
categoryTable.append(row);
}
this.content.append(categoryTable);
}
this.helpOverlay.append(this.content);
console.log(this.content.height());
}
console.log(this.content.height())返回零。
你能發佈你的代碼嗎 – lockdown 2011-06-07 23:51:38
它對我有用。你可以發佈一個jsfiddle它不起作用嗎? (http://jsfiddle.net/2awqM/1/) – 2011-06-07 23:52:22
你的CSS可以派上用場。 – Zlatev 2011-06-08 04:26:09