从<;李>´;标准普尔;检查重复项&。附加它。。。通过jQuery
HTML: jQuery:从<;李>´;标准普尔;检查重复项&。附加它。。。通过jQuery,jquery,text,get,duplicates,Jquery,Text,Get,Duplicates,HTML: jQuery: <li>Tue, 15th May 2012 10:11</li> <li>Tue, 15th May 2012 10:12</li> <li>Tue, 15th May 2012 10:13</li> <li>Tue, 15th May 2012 10:14</li> <li>Tue, 15th May 2012 10:15</li> <li
<li>Tue, 15th May 2012 10:11</li>
<li>Tue, 15th May 2012 10:12</li>
<li>Tue, 15th May 2012 10:13</li>
<li>Tue, 15th May 2012 10:14</li>
<li>Tue, 15th May 2012 10:15</li>
<li>Tue, 16th May 2012 21:08</li>
<li>Tue, 16th May 2012 21:07</li>
<li>Tue, 16th May 2012 21:06</li>
<code></code>
我现在开始这一步,但我不知道如何检查重复的日期和附加唯一的日期
演示:一个选项是使用选择器
$("li").each(function () {
words = $(this).text().split(' ');
xxx = words[1]+" "+words[2]+" "+words[3]+",";
$("code").append(xxx);
});
演示:试试看,它似乎很管用。这样做:-
$("li").each(function() {
words = $(this).text().split(' ');
xxx = words[1] + " " + words[2] + " " + words[3] + ",";
$("code:not(:contains(" + xxx + "))").append(xxx);
});
if ($("code:contains('"+xxx+"')").length == 0)
$("code").append(xxx);
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append(xxx);
else
$("code").append(","+xxx);
}
编辑:
要处理逗号,请尝试以下方法:-
$("li").each(function() {
words = $(this).text().split(' ');
xxx = words[1] + " " + words[2] + " " + words[3] + ",";
$("code:not(:contains(" + xxx + "))").append(xxx);
});
if ($("code:contains('"+xxx+"')").length == 0)
$("code").append(xxx);
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append(xxx);
else
$("code").append(","+xxx);
}
编辑2:
要处理这种类型的输出,请尝试以下方法:-
$("li").each(function() {
words = $(this).text().split(' ');
xxx = words[1] + " " + words[2] + " " + words[3] + ",";
$("code:not(:contains(" + xxx + "))").append(xxx);
});
if ($("code:contains('"+xxx+"')").length == 0)
$("code").append(xxx);
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append(xxx);
else
$("code").append(","+xxx);
}
输出:
$("li").each(function () {
words = $(this).text().split(' ');
xxx = words[1]+" "+words[2]+" "+words[3];
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append('["'+xxx);
else
$("code").append('","'+xxx);
}
});
$("code").append('"]');
如果我需要这样输出,有一件事:[“2012年5月15日”,“2012年5月10日”]