기본적으로 저는 startTime에 하나, endTime에 하나씩 네 개의 timepicker가 있습니다. 시작 시간은 startHour와 startMin으로 구분되며 endTime에도 동일하게 적용됩니다.여러 개의 증가 및 감소 버튼
htmlStr += "<tr><td><input type='button' id='startHourPlus' value='+' class='qtyplus' field='quantity' onClick='plusHour();' /><input type='button' id='startMinPlus' value='+' class='qtyplus' field='quantity' onClick='plusMin();' /><br/>";
htmlStr += "<input type='text' id='startHour' name='quantity' value='0' class='qty' /><input type='text' id='startMin' name='quantity' value='0' class='qty' /><br/>";
htmlStr += "<input type='button' id='startHourMinus' value='-' class='qtyminus' field='quantity' onClick='minusHour();'/><input type='button' id='startMinMinus' value='-' class='qtyminus' field='quantity' onClick='minusMin();' /></td>";
그리고 endTime- 사용자의 경우 :
htmlStr += "<td><input type='button' id='endHourPlus' value='+' class='qtyplus' field='quantity' onClick='plusHour();' /><input type='button' id='endMinPlus' value='+' class='qtyplus' field='quantity' onClick='plusMin();' /><br/>";
htmlStr += "<input type='text' id='endHour' name='quantity' value='0' class='qty' /><input type='text' id='endMin' name='quantity' value='0' class='qty' /><br/>";
htmlStr += "<input type='button' id='endHourMinus' value='-' class='qtyminus' field='quantity' onClick='minusHour();' /><input type='button' id='endMinMinus' value='-' class='qtyminus' field='quantity' onClick='minusMin();' /></td></tr>";
플러스와 마이너스가 클릭하면,이 같은 기능을 공유 여기에 내가 내 startTime을 설정하는 방법입니다. 여기 내 자바 스크립트입니다 :
function plusHour() {
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
if (currentVal < 24) {
$('input[name=' + fieldName + ']').val(currentVal + 1);
}
}
// Otherwise put a 0 there
$('input[name=' + fieldName + ']').val(0);
}
function plusMin() {
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
if (currentVal < 60) {
$('input[name=' + fieldName + ']').val(currentVal + 1);
}
}
// Otherwise put a 0 there
$('input[name=' + fieldName + ']').val(0);
}
function minusHour() {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
$('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
$('input[name=' + fieldName + ']').val(0);
}
}
function minusMin() {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
$('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
$('input[name=' + fieldName + ']').val(0);
}
}
여기 내 바이올린입니다 : Fiddle 첫 번째와 두 번째는 마지막 두 사람은 endTime- 사용자위한, startTime을위한이.
그러나 시작 또는 종료 시간에 증가 및 감소 버튼을 클릭하면 텍스트 상자에 값이 표시되지 않습니다. 내가 잘못한 부분이 궁금합니다.
미리 감사드립니다. 당신이 e.preventDefault();
를 사용하고 있기 때문에
당신은 단순히 'var (current) = parseInt ($ ('input [name = '+ fieldName +'] ') 대신'$ (this))); –
바이올린이 실제로 도움이됩니다. – Yaje
다음은 바이올린입니다. http://jsfiddle.net/BPEC2/ –