我正在查看一段 jQuery 代码:
$(document)
.trigger('someText')
.on('click keyup', someMethod);
我不清楚 .trigger('someText')
会触发什么? someText
指的是什么?我似乎根本无法在代码库中找到它。
文档指出,要使 `.trigger('custom') 有用,您需要第二个参数,但没有。
最佳答案
所有海报都是正确的,该操作会触发自定义事件;请参阅http://api.jquery.com/trigger/
一个例子:
var btn = $('#button');
var box = $('$box');
btn.on('click', function() {
box.trigger('hideBox');
});
box.on('hideBox', function() {
box.hide();
});
关于javascript - 如果没有第二个参数,.trigger ('custom' ) 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47295653/