XML
<content-body-par jcr:primaryType="nt:unstructured" sling:resourceType="foundation/components/parsys">
<text jcr:primaryType="nt:unstructured" jcr:created="2015-10-16T11:23:30.098+08:00" jcr:createdBy="admin" jcr:lastModified="2015-10-16T11:23:42.576+08:00" jcr:lastModifiedBy="admin" sling:resourceType="altera-www/components/general/text" text="<p>mekon</p> " textType="richtext"/>
<mekon jcr:primaryType="nt:unstructured" jcr:created="2015-10-16T10:33:19.218+08:00" jcr:createdBy="admin" jcr:lastModified="2015-10-16T10:33:56.915+08:00" jcr:lastModifiedBy="admin" pubId="00014864-AA" sling:resourceType="altera-www/components/dynamic-modules/mekon" topicId="AA00013077"/>
<mekon_0 jcr:primaryType="nt:unstructured" jcr:created="2015-10-16T11:10:39.230+08:00" jcr:createdBy="admin" jcr:lastModified="2015-10-16T11:10:54.502+08:00" jcr:lastModifiedBy="admin" pubId="000003016-aa" sling:resourceType="altera-www/components/dynamic-modules/mekon" topicId="000003016-aa"/>
<sightly_demandpdf jcr:primaryType="nt:unstructured" jcr:created="2015-10-14T10:28:09.397+08:00" jcr:createdBy="admin" jcr:lastModified="2015-10-14T10:28:09.397+08:00" jcr:lastModifiedBy="admin" sling:resourceType="altera-www/components/included/sightly-demandpdf"/>
</content-body-par>
</jcr:content>
我想使用javascript / jquery获取mekon标签。如果你看一下上面的xml标签,有 mekon 和 mekon_0 。如何从 mekon 标记中获取jrc:created属性值?
预期结果应 2015-10-16T10:33:19.218 + 08:00 和 2015-10-16T11:10:39.230 + 08:00 < / p>
我试过这个
alert($(doc).find('mekon').attr('jcr:created'));
但它只能输出 2015-10-16T10:33:19.218 + 08:00 :(
答案 0 :(得分:0)
经过多次尝试,我得到了渴望的结果
var results = $(doc).find('*').filter(function(){
return this.nodeName.match(/^mekon/i);
}).map(function(){ return $(this).attr('jcr:created');});
$.each(results, function(index, value){
alert(index + " " + value);
});
感谢@Arun P Johny的想法:)