1

您能帮我解决一些 XML 文档的问题吗?

在解析文档时,我已经到了只需要获取相关数据的地步。

这是我正在循环的一组子元素的示例:

<element type="forecast_icon_code">3</element>
<text type="precis">Partly cloudy.</text>
<text type="probability_of_precipitation">10%</text>

$(locationInfo).children().each(function(){
alert($(this).attr("forecast_icon_code"));
});

返回值为“未定义”

4

1 回答 1

3

喜欢:

var attr = $(this).attr("forecast_icon_code");
if (typeof attr !== 'undefined') {
    ..do something with it
}

或者

if ($(this).is('[forecast_icon_code]')) {
    ..have the attribute
}
于 2013-09-15T06:54:16.047 回答