如何为该代码添加回调函数
How to add call back function for this code?
我想知道向下面的函数添加回调函数最简单的方法是什么:
<script>
$(document).on('focus', '#inputbox', function(e) {
$( this).contents().filter(function() {
return this.nodeType === 3;
}).wrap("<span class='new'></span>");
//I tried add function here but it would execute infinite times.
});
</script>
与您已经尝试过的相同,但跳过对cb 的所有冗余调用
<script>
function cb() { alert('Wow!'); }
(function() {
var timer;
var delay = 1000; // call cb delay
$(document).on('focus', '#inputbox', function(e) {
$( this).contents().filter(function() {
return this.nodeType === 3;
}).wrap("<span class='new'></span>");
clearTimeout(timer);
timer = setTimeout(cb, delay);
});
})();
</script>
相关文章:
- 如何向.apply()方法添加回调
- 如何向 chrome 扩展 API 添加回调函数
- 如何为该代码添加回调函数
- 如何在不向现有JavaScript函数添加代码的情况下向该函数添加回调函数
- javascript原型-添加回调
- 如何为每个 AJAX 请求/响应事件添加回调
- 在这种情况下,如何使用参数添加回调
- 为我的简单 JavaScript 函数添加回调功能
- Jquery 可以选择添加回调
- 加载列表(带图像)时添加回调函数
- 如何为setAttribute添加回调
- Google+交互式帖子-如何为按钮添加回调
- 等待异步函数完成而不添加回调
- 向jQuery插件添加回调
- 在forio/control中执行渲染函数后添加回调
- 如何在动态加载javascript文件后添加回调
- 在JavaScript中,可以添加回调函数而不是覆盖它
- 为for循环函数添加回调
- 如何在此函数中为gzip添加回调
- 在JavaScript类中添加回调功能