我有一個元素數組,我希望把它放入一個jQuery對象。 jquery.add()似乎並沒有將元素添加到我的jquery對象中。我有控制檯日誌顯示,我添加的東西確實是html元素,但他們仍然沒有添加在 我做錯了什麼?jquery .add()不添加html元素
我的代碼:
console.log('iterating')
console.log(content)
//add the content into the jquery item, and then we can load it into the qtip
_.each(additionalContent, function(value, element, list){
console.log('adding')
console.log(value)
console.log(content.length)
content.add(value) //trying content.add($(value)) gives the same result/output
console.log(content.length)
})
console.log('asdf')
console.log(content.length)
console.log(content)
====================== 打印以下內容:
iterating
[p.nonVendor unselectable, selector: "", context: undefined, jquery: "1.9.1", constructor: function, init: function…]
adding
<button class type="button" data-loading-text="OK" style="text-align: center; font-style: normal; font-variant: normal; font-weight: normal; font-size: 13px; line-height: normal; font-family: arial; color: rgb(255, 255, 255); background-color: rgb(0, 0, 255); z-index: 2; display: inline; left: auto; top: auto; width: 35.77777862548828px; height: 17.777777671813965px;">OK</button>
1
1
adding
<button class type="button" data-loading-text="Cancel" style="text-align: center; font-style: normal; font-variant: normal; font-weight: normal; font-size: 13px; line-height: normal; font-family: arial; color: rgb(255, 255, 255); background-color: rgb(0, 0, 255); z-index: 2; display: inline; left: auto; top: auto; width: 35.77777862548828px; height: 17.777777671813965px;">Cancel</button>
1
1
asdf
1
[p.nonVendor unselectable, selector: "", context: undefined, jquery: "1.9.1", constructor: function, init: function…]
什麼是「內容」? *編輯*哦,我看到 – Pointy
究竟在哪裏使用'jquery.add()'添加元素? – dreamweiver
內容變量是一個jQuery對象(第2行代碼) – user2099089