간단한 팁 계산기를 만들려고 노력하고 있으며, 이미 가지고있는 코드를 줄이는 방법을 알고 있거나 그 코드를 개선하기위한 제안이 있다면 누구나 기대하고 있습니다.Jquery로 팁 계산기
$(document).ready(function() {
// Five Percent
$('#five').mouseover(function() {
var yourBill = $('#bill_amount').val();
var fivePercent = yourBill * 0.05;
var fiveRounded = fivePercent.toFixed(2)
$('#you_pay').text('$' + fiveRounded);
});
// Ten Percent
$('#ten').mouseover(function() {
var yourBill = $('#bill_amount').val();
var tenPercent = yourBill * 0.10;
var tenRounded = tenPercent.toFixed(2)
$('#you_pay').text('$' + tenRounded);
});
// Fifteen Percent
$('#fifteen').mouseover(function() {
var yourBill = $('#bill_amount').val();
var fifteenPercent = yourBill * 0.15;
var fifteenRounded = fifteenPercent.toFixed(2)
$('#you_pay').text('$' + fifteenRounded);
});
// Twenty Percent
$('#twenty').mouseover(function() {
var yourBill = $('#bill_amount').val();
var twentyPercent = yourBill * 0.20;
var twentyRounded = twentyPercent.toFixed(2)
$('#you_pay').text('$' + twentyRounded);
});
// Twenty Percent
$('#twenty-five').mouseover(function() {
var yourBill = $('#bill_amount').val();
var twentyFivePercent = yourBill * 0.25;
var twentyFiveRounded = twentyFivePercent.toFixed(2)
$('#you_pay').text('$' + twentyFiveRounded);
});
// Back to $0.00
$('a').mouseout(function() {
$('#you_pay').text('$0.00');
});
// Starts with $0.00
$('#you_pay').text('$0.00');
});
당신은 여기 jsFiddle를 볼 수 있습니다 : 여기
코드입니다 http://jsfiddle.net/antwonlee/JXpHe/
이 아마 http://codereview.stackexchange.com/에 대한 – j08691
덕분에 더 잘 맞는 것, 그것이 알고 정말 좋은! –