You needn't attach the event handler in the HTML.
You'll want to keep your JS (jQuery) code seperate from your HTML and to do this you can use the event handling mechanisms available to you in jQuery.
I see @Tatu just posted a code sample as I'm writing this so I wont add the same thing here.
The important part here is to know that you never need to use the HTML event attachment mechanism. It's outdated and rarely has a valid place these days.
-------------------두 이벤트를 모두 바인딩하여 동일한 기능을 수행하십시오.
$(function (){
var myFunc = function(event){
if (event.which >= 38 && event.which <= 40)
return;
var val = $(this).val();
jQTubeUtil.suggest(val, function(response){
var html = '';
for(s in response.suggestions){
var sug = response.suggestions[s];
html += '<li class="uli2"><a href="#">'+sug+'</a></li>';
}
if (response.suggestions.length)
$('#autocomplete').html(html).show();
else
$('#autocomplete').hide();
});
}
$('#searchText2').keyup(myFunc).blur(myFunc);
});
-------------------이 시도 :
다음과 같이 입력 필드에 ID를 추가하십시오.
<input name="q" id='tempId' type="text" onblur="**WHAT DO I PUT HER TO RUN CODE**">
$('#tempId').focus(function() {
// write your code for onfocus here
}).blur(function() {
// write your code for blur here
});
출처
https://stackoverflow.com/questions/7414944