jQuery-检查XML属性是否存在

jQuery-检查XML属性是否存在,jquery,xml,ajax,Jquery,Xml,Ajax,我在HTML中填充一组,根据XML中设置的属性,使用图像或flash电影,如下所示: <article image="" flash="flash/1.swf"></article>// this article has flash only <article image="image/1.jpg" flash=""></article>// this article has image only 如果顺序对您不重要,您应该首先筛选flash属性

我在HTML中填充一组
,根据XML中设置的属性,使用图像或flash电影,如下所示:

<article image="" flash="flash/1.swf"></article>// this article has flash only
<article image="image/1.jpg" flash=""></article>// this article has image only

如果顺序对您不重要,您应该首先筛选flash属性, 而不是图像属性。 否则类似于:

$('#container').append('<article><img src="'+$image+'"/><object><param name="movie" value="'+$flash+'"></object></article>');
.append(“”+($image!=null)?这对我很有效

.append('<article>' + ($image != null) ? <img.. : <object..) + "</article>";

在将属性分配给变量之前,应首先检查该属性是否存在

var $flash = $(this).attr('flash');
if ($flash == null) {
...
}
else {
...
}

这无法正确检查属性是否存在。我认为这里接受的答案是更好的解决方案:[jQuery hasAttr检查元素[duplicate]]上是否存在属性()
if($(this).attr('flash');){

    // this attribute exists 
    // you can also check if its null or not

} else {

    // this attribute does NOT exist
}