簡體   English   中英

jQuery DOM-缺少元素,長度為0

[英]jQuery DOM - Missing elements, lengths 0

需要對DOM / Missing元素有更好的了解。

我用

$(document).ready(function(){ 
// show div tag
});

但是我似乎對DOM中不可用的元素感到困惑。

console.log($(".show_quota").length);     
console.log($(".show_restriction").length); 

兩個長度均為0。因此這些div標簽在我的DOM中不可用。

所以我要尋找什么? 如何在DOM中獲得這些元素? 知道為什么這些HTML表單元素會在DOM中消失嗎?

$(document).ready(function()確保所有html元素都出現在dom中嗎?只要在jquery中正確調用了類和id?

更新1:安裝了Mozilla DOM檢查器-但信息不知所措:)

但是,嘿。。。看好舊的html源代碼(通過帶有Firebug的Inspect Element),並且div標簽沒有顯示出來……所以……難怪jquery命令不起作用。

更新2: html標記通過以下方式處理:

    $('#modal').html("");

        var output = '<div class="modal-content">';
        output += 'some html stuff';
        output += '<div id="show_quota" >'; 
        output += 'some html stuff 2';
        output += '</div>'; 


    $('#modal').append(output);
    $('#modal').reveal();     

更新3:問題已解決;

通過;

  1. 卸載FireQuery(在我的設置中為Buggy)
  2. 改性

      output += '<div id="show_quota" >'; // to line below output += '<div id="show_quota" style="display:inline" >'; 
  3. 這些使標記在單擊復選框時顯示/消失。

將類似的內容添加到DOM ...

<div class="show_quota"></div>
<div class="show_restriction"></div>

class引用 id引用

例如<div id="show_restriction"></div>將使用console.log($("#show_restriction").length);

如果您需要測試,這是一個小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM