【发布时间】:2017-09-17 01:48:49
【问题描述】:
我在 ng-repeat 中有一个 <input type="file">,我想在 ng-repeat 中 <input type="file"> 元素的元素值发生变化时调用一个函数。
我尝试调用$(#"id").change() 函数,但它不起作用。我尝试过使用 ng-change,但是当我使用 ng-change 时,ng-repeat 不起作用。这是我的代码:
在 HTML 中
<div ng-repeat="item in items">
<input type="file" accept="image/*" id="add_{{$index}}"/>
</div>
IN JS
$("#add_images").change(function() {
alert("HI");
}
【问题讨论】:
-
可以使用
ng-change=""或者需要使用事件委托.. -
元素的 ID 也必须是唯一的。所以循环中的静态 ID 不是有效的 html
-
@ArunPJohny 如果 id 是唯一的怎么办。
-
@ArunPJohny
标签: javascript jquery html angularjs