How to call one jquery method from another?
I am new to jquery. How do I call a jquery function from another function. What am I doing wrong below?
$('#search').bind({
// focus: function(){ alert('focused');},
keyup: callAjax开发者_如何学JAVA, // call CallAjax function
});
function callAjax(){
$.ajax({
// perform something here
});
}
How to call callAjax
function on keyup
event?
what you want is probably this ?:
$('#search').keyup(function() {
callAjax();
});
or you can try this:
$('#search').bind('keyup', function() {
callAjax();
});
When the button with ID search is 'on-key-up', this event handler will invoke callAjax..
try with
keyup: function() {
callAjax();
},
$('#search').bind('keyup', callAjax);
Fiddle: http://jsfiddle.net/6G58X/
For me all the code works well:
<input type="text" name="search" id="search"/>
<script type="text/javascript">
function callAjax(){ alert('callAjax'); /* call whatever you want here */ }
$(function(){
$('#search').bind({click: function(){alert('click');}, keyup: callAjax});
});
</script>
精彩评论