Untuff typeError:像htmlspanelement.onclick一样不是功能.当我通过错误单击它时



当我通过错误

单击它时

获取错误:und typeerror:像htmlspanelement.onclick

一样,不是一个函数
//In Controller
    myApp.controller('AppCtrl', ['$scope', '$http', 'chatBotService', function($scope, $http, chatBotService) {
        (function () {
            $scope.like = function (lll) {
                alert("like");
                //lll.previousSibling.style.color = 'gray';
                //lll.style.color = 'green';
            }
        });
           (function () {
            $scope.dislike = function (ddd) {
                alert("dislike");
                //ddd.style.color = 'red';
                //ddd.nextSibling.style.color = 'gray';
            }
           });
    function send_message(message) {
          $("#container").append("<div class='row msg_container base_receive'>" +
           "<div class='avatar'>" + "<img src='bot.png' alt='Chat' style='width:15px;margin-right: 10px;'/>" + "<br/>" +"</div>" + "<div class='col-md-10 col-xs-10'>" +"<div class='messages msg_receive'>" + message + "</div>" +"<small>" + DisplayCurrentTime() + "<small/>" + "<span id='dislike' 
    class='glyphicon glyphicon-thumbs-down gly-flip-horizontal dislike' onclick='dislike(this)' aria-hidden='true'></span>" + "<span id='like' onclick='like(this)' class='glyphicon glyphicon-thumbs-up like' aria-hidden='true'></span>" +  "</div>" + "</div>");
            }
    }]);

删除闭合

$scope.like = function (lll) {
    alert("like");
    //lll.previousSibling.style.color = 'gray';
    //lll.style.color = 'green';
}
$scope.dislike = function (ddd) {
    alert("dislike");
    //ddd.style.color = 'red';
    //ddd.nextSibling.style.color = 'gray';
}

或将其更改为iife

(function () {
    $scope.like = function (lll) {
        alert("like");
        //lll.previousSibling.style.color = 'gray';
        //lll.style.color = 'green';
    }
})();
(function () {
    $scope.dislike = function (ddd) {
        alert("dislike");
        //ddd.style.color = 'red';
        //ddd.nextSibling.style.color = 'gray';
    }
})();

document.getElementById("不喜欢"(。AddeventListener(" click",defike(; document.getElementById(" like"(。addeventListener(" click",like(;

    function dislike() {
        this.style.color = 'red';
        this.nextSibling.style.color = 'gray';
    }
    function like() {         
        this.previousSibling.style.color = 'gray';
        this.style.color = 'green';
    }

最新更新