开发者

manually trigger jquery keyup?

开发者 https://www.devze.com 2023-03-15 20:34 出处:网络
I think I figured it out... see my comment.Sorry.开发者_开发技巧 I have a JSON web service that is called on a certain keyup() event which retrieves some data based on the input.I would like to load

I think I figured it out... see my comment. Sorry.

开发者_开发技巧

I have a JSON web service that is called on a certain keyup() event which retrieves some data based on the input. I would like to load an initial set of data before anything is typed. I'm trying to manually invoke the keyup() as stated in the documentation, but it doesn't seem to do anything.

$('#inputItemName').keyup(function () {
//perform query, display results
});

^^ works great when you type in the box

$('#inputItemName').keyup();

^^ called immediately after document ready function, doesn't seem to do anything.


Works fine for me: http://jsfiddle.net/radu/gD5WL/

$('#test').keyup(function () {
    console.log('hello');
});

$('#test').keyup();

The keyup event is getting called on page load.


$('#inputItemName').trigger('keyup');


Try trigger function.

$('#inputItemName').trigger('keyup');

http://api.jquery.com/trigger/


You are missing a # in selector... try with hash...

$('#inputItemName').keyup();


I think I figured it out... I moved the function that calls the results higher up in the script tag than the keyup() invocation and now it works.


You're missing the hash marker for the id in the second one:

$('#inputItemName').keyup();


Try this:

$('#inputItemName').bind('keyup',function() {
    //stuff
});
0

精彩评论

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