只有在失去焦点时才会触发change()

时间:2012-04-18 13:07:42

标签: javascript jquery ajax jquery-ui

我目前正在使用jQuery的更改功能。只有在文本字段外单击时才会触发更改事件。因此,当我在文本框中插入文本时,没有任何事情发生,但是当我失去对文本字段的关注时,事件就会触发。 不,我想在不必在文本区域外单击的情况下触发事件。

这是我的代码:

 jQuery("#customfield_10000").change(function(){
            crmAccount = jQuery(this).val();
            alert(crmAccount);
            lijstAccounts = [];

                    jQuery.ajax({
                        url: "http://localhost/papa/jQuery/development-bundle/demos/autocomplete/searchAccounts.php?jsonp_callback=?",
                        dataType: 'jsonp',
                        jsonp: "jsonp_callback",
                        data: {
                            featureClass: "P",
                            style: "full",
                            maxRows: 12,
                            name_startsWith: jQuery(this).val()
                            },
                            success: function( data ) {
                                 jQuery.map( data, function( item ) {
                                                            lijstAccounts.push(item.label);
                                                            jQuery('#customfield_10000').trigger(
                                                                'setSuggestions',
                                                            { result : textext.itemManager().filter(lijstAccounts, query) }
                                                            );              
                                    return {
                                        label: item.label,
                                        value: item.value    
                                    }
                                });
                            }
                        });

             });

2 个答案:

答案 0 :(得分:4)

您应该处理input(非IE)或propertchange(仅限IE)或keyup(不会抓住粘贴或拖放)事件。

答案 1 :(得分:1)

您可以使用KeyUp event

$("#abcd").keyup(function(event) {
     //code
});
相关问题