$('body').on('click', '.num_pad_wrap div', function() {
if ($('#ticket_number').text() == '0' && $('#ticket_number').text() != 'C') {
$('#ticket_number').empty();
}
var pressed = ($(this).find('span').text() == 'C') ? $('#ticket_number').text('0') : $(this).find('span').text();
$('#ticket_number').append(pressed);
});

.num_pad_wrap div {
background: black;
color: white;
width: 10px;
float: left;
margin-right: 10px;
padding: 10px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ticket_number">0</div>
<div class="num_pad_wrap">
<div><span>1</span></div>
<div><span>2</span></div>
<div><span>3</span></div>
<div><span>4</span></div>
<div><span>5</span></div>
<div><span>6</span></div>
<div><span>7</span></div>
<div><span>8</span></div>
<div><span>9</span></div>
<div><span>0</span></div>
<div><span>C</span></div>
</div>
&#13;
如何对上面的数字键盘进行限制?假设用户插入的值大于50,结果应为50,如果用户再次点击任意键,它将再次正常工作。我不希望将其重置为零以避免额外的一次点击。
答案 0 :(得分:0)
这是你在找什么?
$('body').on('click', '.num_pad_wrap div', function() {
if ($('#ticket_number').text() == '0' || $('#ticket_number').text() == '50') {
$('#ticket_number').empty();
}
var pressed = ($(this).find('span').text() == 'C') ? $('#ticket_number').text('0') : $(this).find('span').text();
$('#ticket_number').append(pressed);
if ($('#ticket_number').text() > 50) {
$('#ticket_number').text('50');
}
});