javascript - ng-click 功能仅在第一次有效

标签 javascript html angularjs ionic-framework

我在一个 div 上设置了一个简单的 ng-click 函数,一旦单击就会改变另一个 div 的颜色。足够简单,除了它只在我第一次单击 div 时起作用...然后什么都没有:(我只是想获得切换功能的功能,我将在不同的事情上使用它。

HTML:(此代码是循环的一部分)

<img ng-click="changer()" src="{{m.img}}" style="width:100%;min-height:480px;max-height:600px;z-index:1;"> 

...

<div style="background-color:{{colorblur}}; width:100px;height:100px;"></div>

Controller :

$scope.colorblur="red";

  $scope.changer = function () {  
        if($scope.colorblur="red"){
          $scope.colorblur="yellow";
        }
        else{
          $scope.colorblur="red";
        }
    } 

提前致谢:)

最佳答案

改变

 if($scope.colorblur="red"){..

 if($scope.colorblur === "red"){...

关于javascript - ng-click 功能仅在第一次有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35388346/

相关文章:

javascript - epub阅读器ios中的文本突出显示和添加注释功能

javascript - 更改按钮的功能

javascript - 简单的 jquery slideToggle 在任何浏览器中都不起作用

javascript - 如何清除 angularJS 数组

javascript - getStaticProps 中的下一个 Js 上下文参数返回 "{ locales: undefined, locale: undefined, defaultLocale: undefined }"

javascript - 当我在 jQuery 中执行 AJAX 调用时出现 JSON 错误

javascript - 验证不起作用,现在我的网站也坏了

javascript - 如何仅在添加/更改数据库记录时重新加载表内容

javascript - 为什么 CSS 转换发生在 unshift() 而不是 ng-repeat 列表中的 shift()?

javascript - Angularjs删除奇偶选定行中具有不同背景颜色的表行