加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 将占位符绑定到模型会导致ng-change在IE中加载时执

发布时间:2020-12-17 18:00:42 所属栏目:安全 来源:网络整理
导读:使用 angularjs,如果我将输入的占位符绑定到其模型,则在IE中加载文档时会触发change事件.这似乎不正确,我在其他浏览器中没有看到这种行为. JS Fiddle HTML: div ng-app="angularjs-starter" data-ng-controller="MainCtrl"div data-ui-view="viewMain" inpu
使用 angularjs,如果我将输入的占位符绑定到其模型,则在IE中加载文档时会触发change事件.这似乎不正确,我在其他浏览器中没有看到这种行为.

JS Fiddle

HTML:

<div ng-app="angularjs-starter" data-ng-controller="MainCtrl">
<div data-ui-view="viewMain">
    <input 
    placeholder="{{theValue}}" 
    data-ng-model="theValue" 
    data-ng-change="valueChanged(theValue)" />            
</div>

使用Javascript:

var app = angular.module('angularjs-starter',[]);
app.controller('MainCtrl',function($scope) {  
    $scope.valueChanged = function(theValue) {
        alert("Value Change Called On Load in IE.");
    };
});

解决方法

也可以使用内置的 ng-attr-placeholder指令.

ng-attr-placeholder="{{theValue}}"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读