jquery text()/html()无法获取元素内容
jquery源文件已经正确引入,用的1.11.3版本<divid="shoppingCart">numsofgoodsincart:<span>33</span></di...
jquery源文件已经正确引入,用的1.11.3版本
<div id="shoppingCart">nums of goods in cart:<span>33</span></div>
var cart = $("#shoppingCart"),span = $("#shoppingCart>span");
console.log(cart.html()); console.log(cart.text()); console.log(span.html()); console.log(span.text());
输出结果为undefined {空字符串} undefined {空字符串}
不知道是哪里的问题,请各位不吝赐教 展开
<div id="shoppingCart">nums of goods in cart:<span>33</span></div>
var cart = $("#shoppingCart"),span = $("#shoppingCart>span");
console.log(cart.html()); console.log(cart.text()); console.log(span.html()); console.log(span.text());
输出结果为undefined {空字符串} undefined {空字符串}
不知道是哪里的问题,请各位不吝赐教 展开
1个回答
展开全部
span = $("#shoppingCart span")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="jquery.js"></script>
<title>Document</title>
</head>
<body>
<div id="shoppingCart">nums of goods in cart:<span>33</span></div>
<script type="text/javascript">
var cart = $("#shoppingCart"),span = $("#shoppingCart span");
console.log(cart.html());
console.log(cart.text());
console.log(span.html());
console.log(span.text());
</script>
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询