我有两个跨度,单击一个跨度标签后,应该显示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中使用子级访问子级,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33051694/

10-12 07:28