开发者

jQuery debounce, way to pass the element along to the function?

开发者 https://www.devze.com 2023-03-16 16:54 出处:网络
HTML <input class=\"list_item_title mini\" name=\"list_item[title]\" size=\"30\" type=\"text\" value=\"What happens when a user creates a new item?\">

HTML

<input class="list_item_title mini" name="list_item[title]" size="30" type="text" value="What happens when a user creates a new item?">

JS:

function text_2(e) {
  开发者_StackOverflow  console.log(e.val());
};

$(function() {
    $('input.list_item_title').keyup( $.debounce( 250, text_2 ) );
});

e.val() currently doesn't work. how can I pass the input along so I can get the value?

Thanks


e is a reference to the event object [docs], not the input element.

You can get a reference to the input element using event.currentTarget [docs].

After the having a look at the source code, you should also be able to access the element with this (like in any other event handler), so the following should work:

function text_2(e) {
    console.log($(this).val());
};


console.log($(e.target).val());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号