Javascript 单击功能不使用ng,如果
如果我像下面这样使用,我就得到了我需要的。。这是代码Javascript 单击功能不使用ng,如果,javascript,angularjs,Javascript,Angularjs,如果我像下面这样使用,我就得到了我需要的。。这是代码 <style> .moreMenu { position: absolute; right: 0px; z-index: 10; padding: 10px; color: #666; border-radius: 0 0 0 4px; background: #FFF; display: none;
<style>
.moreMenu {
position: absolute;
right: 0px;
z-index: 10;
padding: 10px;
color: #666;
border-radius: 0 0 0 4px;
background: #FFF;
display: none;
border-top: 1px solid #DDD;
}
</style>
<i class="fa fa-ellipsis-v tbButton otherOptions rightSide" aria-hidden="true"></i>
<div class="moreMenu">
heloo
</div>
<script>
$(".otherOptions").click(function () {
$(".moreMenu").slideToggle("fast");
});
</script>
但如果我使用ng if条件
<i class="fa fa-ellipsis-v tbButton otherOptions rightSide" aria-hidden="true" ng-if="member==''"></i>
单击功能不起作用。最好使用ng click,但如果需要使用jQuery的单击事件,可以向正文中添加过滤的单击事件:
$('body').on('click', '.otherOptions', function() {
$('.moreMenu').slideToggle('fast');
});
这将在主体上添加事件处理程序,但仅当事件从otherOptions元素冒泡时才会触发。这是一种使用jQuery事件处理动态内容的方法我解决了这个问题
<i class="fa fa-ellipsis-v tbButton otherOptions rightSide" aria-hidden="true" ng-if=members==''" ng-click="mymore()"></i>
// controller
$scope.mymore = function(){
$(".moreMenu").slideToggle("fast");
}
谢谢大家提供的信息…@我相信你的回答是正确的。但根据我在这里回答的问题,使用ng show而不是ng if angular.modulea,[].controllerac,函数$scope{ }; .其他选择 { 颜色:666; } heloodfg $.otherOptions.clickfunction{ $.moreMenu.slideTogglefast; };
您的代码中没有任何地方使用ng click.$。click具有不同的功能您是否使用angularjs实现应用程序?如果是,那么为什么要使用jquery单击函数?只有当我包含ng If条件而没有If条件时,单击函数才起作用working@athi如果使用ng show,请尝试交换ng。也要欣赏你的作品。但是你知道如果你使用的是ng if,为什么点击不起作用吗?@RameshRajendran我猜与ng show不同的是,ng if没有隐藏内容,而是。由于jQuery不是AngularJS摘要周期的一部分,因此尚未为$呈现div with moreMenu类。。。抓住它