gpt4 book ai didi

javascript - 在 jQuery 中使用children访问children

转载 作者:行者123 更新时间:2023-11-28 18:58:45 25 4
gpt4 key购买 nike

我有两个跨度,单击一个跨度标签时,应显示 p 标签。这是我的 HTML 文件:

<span class="span1" ng-click="show()">Span_1
<p class="p1" ng-show="var1">P_1</p>
</span>
<span class="span1" ng-click="show()">Span_2
<p class="p2" ng-show="var1">P_2</p>
</span>

对应的jQuery是

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.var1 = false;
$("span").click(function(){
$(this).children().toggle();
})
});

Angularjs中也有children()标签吗?笨蛋是 http://plnkr.co/edit/UnyqbY6lLRqhAb8183Nf?p=preview

最佳答案

请查看plunker

<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<span class="span1">Span_1
<p class="p1" style="display:none;">P_1</p></span><br>
<span class="span1" >Span_2
<p class="p2" style="display:none;">P_2</p></span>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$("span").click(function(){
console.log($(this).children())
$(this).children().first().toggle();
})
});
</script>

</body>
</html>

关于javascript - 在 jQuery 中使用children访问children,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33051694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com