js/jq - text方法,获取文本设置文本

1、设置文本值

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn2").click(function(){
    $("p").text("66666666666666");
  });
});
</script>
</head>
<body>
<p>hhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhh</p>
<button class="btn2">改变所有 p 元素的文本内容</button>
</body>
</html>

2、获取文本值

 $(".btn1").click(function(){
    alert($("p").text());
  });

3、待续

猜你喜欢

转载自blog.csdn.net/sinat_32238399/article/details/82804657