2014-02-17 54 views
0

我有一個ul列表,並希望對它們執行搜索,此列表會彈出一個ddSlick下拉框。 ddSlick是將圖片添加到列表項目的好方法。 http://designwithpc.com/Plugins/ddSlick如何從ul ul項目中獲取文本?

雖然項目如下:我使用循環中的代碼:

$("#txtSearch").blur(function() { 
    $('#MarkieItems').each(function(i, items_list){ 
    $(items_list).find('li').each(function(j, li){ 
    //alert(li.TextContent); 
    var text = li.TextContent; 
    }) 
}); 

當我檢查元素,並期待在文本= li.TextContent它說undifined,但如果我檢查了李它顯示textContent在那裏。

enter image description here

enter image description here

有人能告訴我如何抓住這個文本?

+0

是因爲它應該是textContent(); ? –

+1

我想,應該是li.textContent(小't') – Vinoth

+0

Omw我不敢相信我錯過了。謝謝Vinoth。 – Pomster

回答

2
$('#MarkieItems li').each(function(){ 
    var text = $(this).text(); 
}) 
+0

非常感謝。 – Pomster

1

您試圖訪問li.TextContent但是屬性是根據您的屏幕轉儲稱爲textContent即用小寫字母t

既然你已經使用jQuery,你可以利用文本方法

var text = $(this).text(); 
1

如果您有jQuery的你可以使用text()抓住從裏只有文字。

1

使用textContent,而不是TextContent bcoz這是區分大小寫

1

你寫的TextContent在JavaScript中PascalCase,而你應該在駝峯寫。

嘗試

var text = li.textContent; 
1

試試這個:

$("#txtSearch").blur(function() { 
    $('#MarkieItems').each(function(i, items_list){ 
    $(items_list).find('li').each(function(j, li){ 
    //alert(li.TextContent); 
    var text = li.text(); //<-----here ".text()" 
    }) 
}); 

.text()的jQuery的方法將讓你的目標DOM節點的的textContent。