如何给动态按钮添加绑定对应的点击事件?

代码如下,ajax拿到数据后,用for循环生成了一堆按钮,现在需要给每一个按钮添加不一样的点击事件,该如何实现与修改?比如生成了1,2,3,4。4个按钮,点击1,打印1,点击2,打印2…

            for(var i = 0; i < data.length; i++) { //生成按钮
                     attrTypeArr.push(data[i].attrType);
                        jQuery("#attrTpyeWrap").append("<a class='btn-xs btn-default type'>" + data[i].attrType + "</a>" + "|");        
                    }
            jQuery(".type").on("click",function(){
                        console.log("1")                            
                 });
for(var i = 0; i < data.length; i++) { //生成按钮
                 attrTypeArr.push(data[i].attrType);
                    jQuery("#attrTpyeWrap").append("<a class='btn-xs btn-default type'  onClick=“test();”>" + data[i].attrType + "</a>" + "|");        
                }

             });

                            function test(){
                                console.log("1") 
                            }
 for(var i = 0; i < data.length; i++) { //生成按钮
                 attrTypeArr.push(data[i].attrType);
                    jQuery("#attrTpyeWrap").append("<a class='btn-xs btn-default type'  onClick=“test(this,'+i+');”>" + data[i].attrType + "</a>" + "|");        
                }

             });

                            function test(a,i){
                                console.log(a.innerHTML+'\n'+i) 
                            }