0

SUre I am missing something with this Jquery. Suppose I have a list of n words as so : <div class ="text"><p>word(n)</p></div>. I want to alert each of the words so I put simply :

var string= $('.text p');
string.each(function(){ldelim}
alert($(this).val());
{rdelim}
);

{rdelim} and {ldelim} are just left braces and right braces because I use smarty. But the alert returns an empty message. Someone could help ?

4

4 回答 4

3

您应该使用text方法,val用于设置/获取表单元素的值:

alert($(this).text());
于 2012-12-15T11:23:36.863 回答
1
var string= $('.text p');
string.each(function(i,v){ldelim}
    alert($(v).text());
{rdelim}
);

这应该工作:)

于 2012-12-15T11:23:49.577 回答
1

使用此流程:

var string= $('.text p');
 $.each(string,function(k,v){                        
 alert(v.text());
});
于 2012-12-15T11:24:48.767 回答
0

试试这种方式:

$(function(){

$.each($('.text p'),function(){
alert($(this).html())
});

});
于 2012-12-15T11:32:43.753 回答