jQuery DOM 元素方法(get)

jQuery DOM 元素方法

1、.get() 获得由选择器指定的 DOM 元素。 

$(selector).get(index)
index 可选。规定获取哪个匹配元素(通过 index 编号)。

实例

获得第一个 p 元素的名称和值:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
  $("button").click(function(){
  x=$("p").get(0);
  $("div").text(x.nodeName + ": " + x.innerHTML);
});
});
</script>
</head>
<body>
  <p>This is a paragraph</p>
  <button>获得 p DOM 元素</button>
<div></div>
</body>
</html>

运行结果:
P: This is a paragraph
 

posted on 2017-07-17 09:17  michellexiaoqi  阅读(247)  评论(0编辑  收藏  举报