html代码
<div class="dnbc_box"> <span class="dnbcb_sub" id="sub">-</span> <input type="text" value="1" class="dnbcb_inps" id="inp"> <span class="dnbcb_add" id="add">+</span> </div>
js代码
function getId(ogbId) {
return document.getElementById(ogbId);
}
var sub = getId('sub');
var add = getId('add');
var inp = getId('inp');
var inpValue = parseInt(inp.value);
sub.onclick = function() {
if (inp.value > 1) {
inp.value--;
}
if (inp.value == 1) {
sub.style.color = '#999';
}
}
add.onclick = function() {
inp.value++;
sub.style.color = '#333';
}