例如,如果我有下一个事件:
document.getElementById('TagSearchInput').onkeyup = function(e)
{
//Code...
}
在事件内部,有一个条件需要我重新创建元素 (TagSearchInput
)。如何从事件内部刷新事件选择器?
最佳答案
好的,忽略任何关于为什么要重新创建输入的问题...
不要使用匿名函数,尝试这样的方法:
function TSIKeyupHandler(e)
{
//Code...
// within your condition where you want to re-attach the handler
document.getElementById('TagSearchInput').onkeyup = TSIKeyupHandler;
}
document.getElementById('TagSearchInput').onkeyup = TSIKeyupHandler;
(如果您想让 TSIKeyupHandler()
函数保持在全局范围之外,可以选择将上述所有内容放入立即调用的匿名函数中。)
关于javascript - JS元素事件,刷新元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11303785/