zoukankan      html  css  js  c++  java
  • ng-click得到当前元素,

    直接上代码:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script src="../plugins/jquery/jquery.js"></script>
        <script src="../plugins/angular/angular.js"></script>
    </head>
    <body ng-app="AngularApp">
    <div ng-controller="TestCtrl">
        <a href data="1" ng-click="GoPage($event.target)">1</a>
        <a href data="2" ng-click="GoPage($event.target)">2</a>
        <a href data="3" ng-click="GoPage($event.target)">3</a>
        <a href data="4" ng-click="GoPage($event.target)">4</a>
        <a href data="5" ng-click="GoPage($event.target)">5</a>
        {{ page }}
    </div>
    <script>
        var _app=angular.module("AngularApp",[]);
        function TestCtrl($scope) {
            $scope.page = 1;
            $scope.getData = function () {
                console.log($scope.page);
            }
            $scope.GoPage = function (target) {
                $scope.page = target.getAttribute('data');
                this.getData();
            }
        }
        _app.controller("TestCtrl",TestCtrl);
    </script>
    </body>
    </html>

    其中:target获取到的是点击对象的html字符串,可以通过jquery中$(target)这种形式将字符串转换为dom对象。然后就可以随意进行操作啦。

  • 相关阅读:
    Lua metatable & metamethod
    lua 中的点、冒号与self
    Eclipse 快捷键
    logging的使用
    URL转义字符
    UnicodeEncodeError: ‘ascii’ codec can’t encode
    Baidu URL的部分参数
    使用JS伪造Post请求
    print 不换行
    exception keynote
  • 原文地址:https://www.cnblogs.com/RuMengkai/p/6379419.html
Copyright © 2011-2022 走看看