Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery没有';在ng repeat中找不到特定元素_Jquery_Html_Angularjs - Fatal编程技术网

jquery没有';在ng repeat中找不到特定元素

jquery没有';在ng repeat中找不到特定元素,jquery,html,angularjs,Jquery,Html,Angularjs,从下面的html代码开始 <div ng-repeat="item in list"> <input type="text" class="texter"> </div> 但什么也没发生。即使 $('input').keypress(function(e){ console.log(this); } 基本上,我想获取触发keypress事件的元素 有没有办法通过jquery获得它 请注意,我在询问之前已经搜索了答案,但似乎没有一个答案符合我

从下面的html代码开始

<div ng-repeat="item in list">
    <input type="text" class="texter">
</div>
但什么也没发生。即使

$('input').keypress(function(e){
    console.log(this);
}
基本上,我想获取触发keypress事件的元素

有没有办法通过jquery获得它


请注意,我在询问之前已经搜索了答案,但似乎没有一个答案符合我的预期。

为什么要使用jQuery绑定事件侦听器?通过在
ng repeat

棱角的

HTML

如果坚持使用jQuery处理事件绑定,则应使用
$(document).on('keypress',…)

$(document).on('keypress', '.texter', function(e){
  console.log(e);
});

这就是为什么混合使用jQuery和Angular不是一个好主意——每次Angular重新绘制DOM时,它都会吹走它不知道的jQuery事件绑定。改为在Angular中处理按键事件。请尝试使用
$timeout
包装它。它无法抓取您的类,因为它们尚未呈现。jQuery不是呈现摘要周期的一部分。DOM修改是针对指令的,这些指令使用可以尝试使用的JQLite。我建议使用$(document)。on('keypress','.texter',function(){console.log($(this))})workso我如何处理angular按键事件?使用
委托
已经有一段时间被弃用了…更新了答案,在上使用
,我认为这不应该被标记为重复帖子。这是对链接帖子的部分回答,因为它与Angular相关,而jQuery不应用于绑定。可能会将标题更改为更具上下文和相关性的内容“如何将按键事件绑定到ng repeat中的输入”
<div ng-repeat="item in list">
  <input type="text" class="texter" ng-keypress="keypress($event)">
</div>
angular
  .module("myApp", [])
  .controller('myController', ['$scope', function($scope) {

    $scope.list = [1,2,3];

    $scope.keypress = function(event){
      console.log(event);
    }
  }]);
$(document).on('keypress', '.texter', function(e){
  console.log(e);
});