This script does what it proposes. It inserts the clicked button signal and keeps the cursor focused on the field.
I suggest to simplify the code: instead of using two functions for each button, use only one:
$('#mais, #menos').click(function(e){
insereSinal('#console', e.target.textContent);
});
$('#mais, #menos').click(function(e){
insereSinal('#console', e.target.textContent);
});
function insereSinal(cId, sinal){
var cam = $(cId)[0];
var cvl = $(cam).val();
var cps = cam.selectionStart;
var ini = cvl.substring(0, cps);
var fim = cvl.substring(cps, cvl.length);
$(cam).val(ini+sinal+fim);
cps += sinal.length;
cam.selectionStart = cam.selectionEnd = cps;
cam.focus();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="console" type="text">
<button id="mais">+</button>
<button id="menos">-</button>
If you want the compressed function:
$('#mais,#menos').click(function(e){insereSinal('#console',e.target.textContent);});
function insereSinal(cId,sinal){var cam=$(cId)[0];var cvl=$(cam).val();
var cps=cam.selectionStart;var ini=cvl.substring(0,cps);
var fim=cvl.substring(cps,cvl.length);$(cam).val(ini+sinal+fim);
cps+=sinal.length;cam.selectionStart=cam.selectionEnd=cps;cam.focus();}
Compatibility: IE9 +, Edge, FF, Chrome, Safari, Opera
Source: SOen (with adaptations and considerable code reduction)