在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ addEventListener 調(diào)用函數(shù)兩種寫法區(qū)別

addEventListener 調(diào)用函數(shù)兩種寫法區(qū)別

// 寫法一
let input1 = document.getElementById('input1');
let output1 = document.getElementById('output1');
input1.addEventListener('input', debounce(function() {
  output1.value = (input1.value || '').toUpperCase();
},
500));
// 寫法二
let input2 = document.getElementById('input2');
let output2 = document.getElementById('output2');
input2.addEventListener('input', debounceTrigger);

function debounceTrigger() {
  debounce(function() {
    output2.value = (input2.value || '').toUpperCase();
  },
  500)()
}

第一種寫法正常,第二種寫法就不行。
如果用第二種寫法,如何能實(shí)現(xiàn)和第一種寫法一樣的效果?

可進(jìn)入以下頁(yè)面調(diào)試
jsrun

回答
編輯回答
心沉

你的函數(shù)沒有返回值。

function debounceTrigger() {
  return debounce(function() {
    output2.value = (input2.value || '').toUpperCase();
  },
  500)
}
input2.addEventListener('input', debounceTrigger());
2017年12月14日 14:51