<div id='my_div' class='layer' style='position: absolute; top: 30px; left: 15px'>
</div>
<script>
arr = [1, 2, 'Банан'];
div = document.getElementById('my_div');
for (i=0; i<arr.length; i=i+1)
div.innerHTML += '<input type="button" value="продать" onclick=" Pocupca('+arr[i]+'); ">';
document.querySelectorAll('input[type="button"]')[2].onclick = function(){
alert(arr[2]);
};
function Pocupca(p)
{
alert (p);
}
</script>