如何获得根元素的属性? [英] how can get attributes of root element?

查看:121
本文介绍了如何获得根元素的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?xml version="1.0" encoding="UTF-8"?>
<data columns="12" rows="0"/>

如何获取根(数据)元素的属性(行) 在jQuery中?

how can get attributes (rows) of root (data) element in jquery?

我可以

var records = $(xml).find(":first").parent().attr("rows");

但不起作用:-/

谢谢 罗布

推荐答案

如果它是根节点,请使用.filter()代替.find().

If it is a root node, use .filter() instead of .find().

var records = $(xml).filter(":first").attr("rows");

  • http://api.jquery.com/filter/
    • http://api.jquery.com/filter/
    • jQuery的.find()通过在内部 中搜索根节点进行选择,而.filter() 中选择根节点.

      jQuery's .find() selects by searching inside the root nodes, while .filter() selects from among the root nodes.

      这篇关于如何获得根元素的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆