Javascript 按键事件在magento中不起作用

Javascript 按键事件在magento中不起作用,javascript,jquery,magento,Javascript,Jquery,Magento,我在按键事件方面遇到问题。首先我输入了键,然后它工作,但下次输入键不工作。请告诉我我的代码出了什么问题: html代码: <div class="findbysku"> <input type="text" class="input-text" name="q" id="finder" title="Model #" onblur="if (this.value == '') { this.value = this.defaultVa

我在按键事件方面遇到问题。首先我输入了键,然后它工作,但下次输入键不工作。请告诉我我的代码出了什么问题:

html代码:

      <div class="findbysku">
                <input type="text" class="input-text" name="q" id="finder" title="Model #" onblur="if (this.value == '') { this.value = this.defaultValue;}" onfocus="if (this.value == this.defaultValue) {this.value = '';}" value="Model #" on/> 
                <button class="button" title="Search" id="finder_find" type="submit">Search</button>
            </div>
javascript代码:
type="text/javascript"></script>
<script type="text/javascript" >

     $.noConflict(); 
    jQuery(document).ready(function(){

    var options, a;
    jQuery(function(){
        options = { serviceUrl:'<?php echo $url; ?>finder/index/loadproductsbyquery', 
                    onSelect: function(value, data){ open_product(data);  },
                    maxHeight:400,
                    minChars:3,
                    width:300,
                    noCache: false
                  };
        a = jQuery('#finder').autocomplete(options);
    });          

    jQuery('#finder').keypress(function(event) {

        if (event.keyCode == 13) {

           if (a.data.length > 0 ) {

               open_product(a.data[0]);

           }
        }
    });

    jQuery('#finder_find').click(function() {  

           if (a.data.length > 0 ) {    

               open_product(a.data[0]);
           }        

    });

    jQuery('.list-categories select').change(function() {
        window.open(jQuery(this).val(),'_self');    
    }); 
});

jQuery("#sample-review-click").fancybox({
    padding : 0  
});

jQuery("#guidelines-click").fancybox({
    autoSize    : true,
    maxWidth    : 600,

}); 
function open_product(data) {

    jQuery('.product-container').css('background-color','#FFFFFF');
    jQuery.post('<?php echo $url; ?>finder/index/getproductinfo',{ id: data} , function(response) {
        var response_array=JSON.parse( response );                   
        var url=response_array.url+"#box-Reviews";
        window.location.href = url;
    });             
}   

</script>
按键事件运行正常。可能是其他问题

  $.noConflict(); 
jQuery(document).ready(function(){
jQuery('#finder').on('keypress',function(event) {
        alert(event.keyCode)
        if (event.keyCode == 13) {

           if (a.data.length > 0 ) {

               open_product(a.data[0]);

           }
        }
    });

})
注意:按与按键事件相关的事件顺序:

    keydown - The key is on its way down
    keypress - The key is pressed down
    keyup - The key is released
但是,并非所有按键都触发按键事件,例如ALT、CTRL、SHIFT、ESC。使用keydown方法也可以检查这些键