标签: events

使用jQuery触发按键事件的明确方法

我已经阅读了关于这些问题的所有答案,但没有一个解决方案似乎有效.

此外,我正在获得触发按键的特殊字符的氛围根本不起作用.有人可以验证谁做了这个吗?

jquery events triggers keypress

254
推荐指数
5
解决办法
27万
查看次数

ng-repeat完成后调用函数

我想要实现的基本上是"on ng repeat finished rendering"处理程序.我能够检测到它何时完成,但我无法弄清楚如何从中触发一个功能.

检查小提琴:http://jsfiddle.net/paulocoelho/BsMqq/3/

JS

var module = angular.module('testApp', [])
    .directive('onFinishRender', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attr) {
            if (scope.$last === true) {
                element.ready(function () {
                    console.log("calling:"+attr.onFinishRender);
                    // CALL TEST HERE!
                });
            }
        }
    }
});

function myC($scope) {
    $scope.ta = [1, 2, 3, 4, 5, 6];
    function test() {
        console.log("test executed");
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div ng-app="testApp" ng-controller="myC">
    <p ng-repeat="t in ta" on-finish-render="test()">{{t}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

答案:来自finishmove的工作小提琴:http …

events directive handler ready angularjs

250
推荐指数
5
解决办法
14万
查看次数

C#事件和线程安全

UPDATE

从C#6开始,这个问题的答案是:

SomeEvent?.Invoke(this, e);
Run Code Online (Sandbox Code Playgroud)

我经常听到/阅读以下建议:

在检查事件之前,请务必复制事件null并将其触发.这将消除线程的潜在问题,其中事件变为null位于您检查null和触发事件的位置之间的位置:

// Copy the event delegate before checking/calling
EventHandler copy = TheEvent;

if (copy != null)
    copy(this, EventArgs.Empty); // Call any handlers on the copied list
Run Code Online (Sandbox Code Playgroud)

更新:我从阅读中了解到这可能还需要事件成员的优化,但Jon Skeet在他的回答中指出CLR不会优化副本.

但同时,为了解决这个问题,另一个线程必须做到这样的事情:

// Better delist from event - don't want our handler called from now on:
otherObject.TheEvent -= OnTheEvent;
// Good, now we can be certain that OnTheEvent will not run...
Run Code Online (Sandbox Code Playgroud)

实际的顺序可能是这种混合物:

// Copy the event delegate before checking/calling
EventHandler copy …
Run Code Online (Sandbox Code Playgroud)

c# events multithreading

230
推荐指数
6
解决办法
8万
查看次数

jquery选择更改事件获取选定选项

我用我的选择元素的更改事件绑定了一个事件:

$('select').on('change', '', function (e) {

});
Run Code Online (Sandbox Code Playgroud)

如何在更改事件发生时访问已选择的元素?

jquery events

228
推荐指数
6
解决办法
48万
查看次数

如何删除lambda事件处理程序

可能重复:
在C#中取消订阅匿名方法
如何取消注册"匿名"事件处理程序

我最近发现我可以使用lambdas来创建简单的事件处理程序.我可以订阅像这样的点击事件:

button.Click += (s, e) => MessageBox.Show("Woho");
Run Code Online (Sandbox Code Playgroud)

但你怎么取消订阅呢?

c# events lambda event-handling

223
推荐指数
1
解决办法
8万
查看次数

如何在Android中捕获"虚拟键盘显示/隐藏"事件?

我想根据是否显示虚拟键盘来改变布局.我搜索过API和各种博客,但似乎找不到任何有用的东西.

可能吗?

谢谢!

events android android-softkeyboard

219
推荐指数
10
解决办法
17万
查看次数

如何在JavaScript中捕获右键单击事件?

我想阻止标准上下文菜单,并手动处理右键单击事件.

这是怎么做到的?

html javascript events event-handling javascript-events

218
推荐指数
2
解决办法
26万
查看次数

Angular中的全球事件

有没有相当于$scope.emit()$scope.broadcast()在角?

我知道EventEmitter功能,但据我所知,它只会向父HTML元素发出一个事件.

如果我需要在fx之间进行通信怎么办?兄弟姐妹或DOM根目录中的一个组件和一个嵌套了几层深层的元素?

events angular

218
推荐指数
5
解决办法
12万
查看次数

jQuery .live()vs .on()方法,用于在加载动态html后添加click事件

我正在使用jQuery v.1.7.1,其中.live()方法显然已被弃用.

我遇到的问题是,当使用以下方法动态将html加载到元素中时:

$('#parent').load("http://..."); 
Run Code Online (Sandbox Code Playgroud)

如果我之后尝试添加click事件,则不会使用以下任一方法注册事件:

$('#parent').click(function() ...); 
Run Code Online (Sandbox Code Playgroud)

要么

// according to documentation this should be used instead of .live()
$('#child').on('click', function() ...); 
Run Code Online (Sandbox Code Playgroud)

实现此功能的正确方法是什么?它似乎只适用于.live(),但我不应该使用该方法.请注意,#child是动态加载的元素.

谢谢.

javascript jquery events dom handler

209
推荐指数
6
解决办法
15万
查看次数

jQuery - 从DOM中删除元素时的触发事件

我试图弄清楚当从页面中删除元素时如何执行一些js代码:

jQuery('#some-element').remove(); // remove some element from the page
/* need to figure out how to independently detect the above happened */
Run Code Online (Sandbox Code Playgroud)

是否有为此量身定制的活动,例如:

jQuery('#some-element').onremoval( function() {
    // do post-mortem stuff here
});
Run Code Online (Sandbox Code Playgroud)

谢谢.

jquery events dom triggers

203
推荐指数
7
解决办法
14万
查看次数