manually trigger jquery keyup?
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
});
精彩评论