【问题标题】:Javascript . Uncaught ReferenceError: OnChange is not definedJavascript 。未捕获的 ReferenceError:未定义 OnChange
【发布时间】:2017-09-11 20:27:26
【问题描述】:
<select name="Connection" id="dropConnection"  ng-change="connectionChange(this)" ></select> 

下面是脚本。

var app = angular.module('myApp', ['angular.filter']);
app.controller('customersCtrl', function($scope, $http) {

    function connectionChange(sel)
      {
        var connectionName = sel.options[sel.selectedIndex].text;
        alert("connectionName");
      }
});

下拉内容是从 json respose 添加的,并且一切正常。错误是:

Uncaught ReferenceError: OnChange is not defined
    at HTMLSelectElement.onchange 

【问题讨论】:

标签: javascript angularjs


【解决方案1】:

不是onchange,而是ng-change。在此处查看更多信息ngChange。并删除你的内在功能

var app = angular.module('myApp', ['angular.filter']);
app.controller('customersCtrl', function($scope, $http) {
    var connectionName = sel.options[sel.selectedIndex].text;
    alert("connectionName");
});

【讨论】:

    【解决方案2】:

    你必须像这样在 $scope 中添加函数

     $scope.connectionChange = function (sel){
        var connectionName = sel.options[sel.selectedIndex].text;
        alert("connectionName");
      }
    

    也为您的 html 使用 ng-change

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2023-01-23
      • 2016-11-03
      • 2011-01-05
      • 2016-01-02
      • 2013-10-06
      相关资源
      最近更新 更多