jQuery事件委派输入类型keyup模糊

时间:2016-06-11 00:23:31

标签: jquery event-delegation

$('#item_code_wrapper').on('keyup blur', '#item_code', function(){

            if( $(this).val() != ""){

                $.ajax({
                    url : "../item/code/" + $(this).val(),
                    success: function(data){

                        if (data.success == 'false') {
                            $('#item_description option').removeAttr('selected');
                        }else{
                            $('#item_description option:eq(' + data.item_id + ')').attr('selected', true);
                        }

                    }
                });

            }

        });

如果我复制并粘贴代码,则可以使用此功能。它指向带有项ID的选项,如果数据成功为false,它也会删除所选项。但话说回来,如果我手动输入商品代码并且具有匹配的ID,则会将选项更改为选中但不会指向该特定选项。

0 个答案:

没有答案
相关问题