【问题标题】:Angularjs input not working on IE 9/8Angularjs 输入在 IE 9/8 上不起作用
【发布时间】:2015-12-13 08:54:54
【问题描述】:

此代码似乎适用于除 IE 9 和 8 之外的所有其他浏览器 - 谁能说出这是为什么?

它没有获取用户在文本字段中输入的值,而是忽略模型并输入我在控制器中输入的值。

HTML:

<input type="text" ng-model="input.value" ng-disabled="input.disabled"/>
<a ng-show="input.button" ng-click="saveInput(input.value)" class="button">Submit value</a>

功能:

$scope.input.value = 0;
    $scope.saveInput = function(val){
                var url = $scope.apiServer +
                '/user/pushValue?user=' + userID +
                '&month=' + prevMonth + '&value=' + val;
                $http.jsonp(url + '&callback=JSON_CALLBACK')
                    .success(function (data) {
                        $scope.input.confirm = 'Great! Your answer of ' + val + ' has been submitted for' + prevMonthLong;
                    })
            }

【问题讨论】:

  • 你有什么错误吗?请在 IE 控制台窗口中查看。

标签: angularjs internet-explorer-8 internet-explorer-9


【解决方案1】:

只需在控制器中全局定义 $scope.input={} 对象即可。

喜欢

**$scope.input={};**
$scope.input.value = 0;
    $scope.saveInput = function(val){
                var url = $scope.apiServer +
                '/user/pushValue?user=' + userID +
                '&month=' + prevMonth + '&value=' + val;
                $http.jsonp(url + '&callback=JSON_CALLBACK')
                    .success(function (data) {
                        $scope.input.confirm = 'Great! Your answer of ' + val + ' has been submitted for' + prevMonthLong;
                    })
            }

如果您在 IE 控制台窗口上遇到任何错误,请告诉我。

【讨论】:

  • 不幸的是,这不起作用,我在控制台中没有收到任何错误日志。看起来浏览器忽略了更新的模型,只是解析了原始值 0。
【解决方案2】:

您的HTML

    <input type="text" ng-model="input.value" ng-disabled="input.disabled"/>
    <a ng-show="input.button" ng-click="input.saveInput(input.value)" 
class="button">Submit value</a>

你的控制器看起来像

    var input ={value : 0};
     input.saveInput = function(val){
                    var url = $scope.apiServer +
                    '/user/pushValue?user=' + userID +
                    '&month=' + prevMonth + '&value=' + val;
                    $http.jsonp(url + '&callback=JSON_CALLBACK')
                        .success(function (data) {
                            input.confirm = 'Great! Your answer of ' + val + ' has been submitted for' + prevMonthLong;
                        })
                }
$scope.input=input;

我也鼓励你在控制器中使用对象字面量,而不是所有东西都与 $scope 绑定。所以首先创建一个对象,然后在你的控制器末尾,你可以绑定它 $scope.这是一个很好的做法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 2013-12-27
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多