๊ฒŒ์ž„/ํ”ผํŒŒ์˜จ๋ผ์ธ4

ํ”ผํŒŒ์˜จ๋ผ์ธ ์ˆ˜์ˆ˜๋ฃŒ๊ณ„์‚ฐ๊ธฐ ์ฝ”๋“œ๋ฆฌ๋ทฐ(Code Review) ๋ฐ ์„ค๋ช…

๐Ÿป๊ณฐ์ด๐Ÿป 2022. 10. 4.
728x90

์•ˆ๋…•ํ•˜์„ธ์š” ๊ณฐ์ด์—์š”!

 

์˜ค๋Š˜ ์ž ๊น ์‹ฌ์‹ฌํ•ด์„œ ๋งŒ๋“ค์–ด๋ณธ ํ”ผํŒŒ์˜จ๋ผ์ธ ์ˆ˜์ˆ˜๋ฃŒ ๊ณ„์‚ฐ๊ธฐ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฐ ์„ค๋ช…์„ ํ•ด๋ณผ๊นŒ ํ•ฉ๋‹ˆ๋‹ค.

 

์ด๋Ÿฐ ๊ฒŒ ์ œ ๋ธ”๋กœ๊ทธ์—์„œ๋Š” ์ฒ˜์Œ์ด๋ผ ์ž˜ ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ์„์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š” ใ…Žใ…Ž

 

 

[ํ”ผํŒŒ์˜จ๋ผ์ธ4] ํ”ผํŒŒ์˜จ๋ผ์ธ ์ˆ˜์ˆ˜๋ฃŒ๊ณ„์‚ฐ๊ธฐ ์‹ฌ์‹ฌํ•ด์„œ ๋งŒ๋“ค์–ด๋ด„

์•ˆ๋…•ํ•˜์„ธ์š” ๊ณฐ์ด์—์š” :) ์˜ค๋Š˜์€ JS/JQ๋กœ ํ”ผํŒŒ์˜จ๋ผ์ธ 4 ์ˆ˜์ˆ˜๋ฃŒ ๊ณ„์‚ฐ๊ธฐ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งŒ๋“ค์–ด๋ดค์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ  ์‚ฌ์ดํŠธ https://fifaonline4.nexon.com/common/calculator EA SPORTS™ FIFA ONLINE 4 fifaonline4.nexon.com ๋งŒ๋“ค๊ณ  ๋‚˜์„œ

easy-developmentbear.tistory.com

์ž‘๋™์€ ์œ„์— ํฌ์ŠคํŒ… ํƒ€์‹œ๋ฉด ๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

๊ณ ์•ˆํ•œ ์ด์œ 

 

์ด์œ ๋Š” ๋”ฑํžˆ ์—†์–ด์š” ๊ทธ๋ƒฅ ํ•œ๋ฒˆ ํ•ด๋ณผ๊นŒ ํ•ด์„œ ๋„์ ์ด๋ฉด์„œ ๋งŒ๋“  ๊ฒ๋‹ˆ๋‹ค.

 

 

์ „์ฒด ์†Œ์Šค

 

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>ํ”ผํŒŒ ์ˆ˜์ˆ˜๋ฃŒ ๊ณ„์‚ฐ๊ธฐ</title>
</head>
<script src="/js/jquery-3.4.1.min.js"></script>
<script src="/js/jquery_ui/jquery-ui.min.js"></script>
<script>
//input์— ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›๊ธฐ
function isNum()
{
	if ((event.keyCode >= 45 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8|| event.keyCode==13 || event.keyCode==9) return true;
	else return false;
}

//์ฒœ ๋‹จ์œ„ ์ฝค๋งˆ ์ฐ์–ด ์ถœ๋ ฅํ•˜๊ธฐ
function number_format(val)
{
	var val_in = val.toString().split(".");
	val_in[0] = val_in[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	val_in = val_in.join(".");

	return val_in;
}

//๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
function get_data(double) 
{
	//์ž…๋ ฅ ๊ฐ€๊ฒฉ
	var put_bp = double.toString();
	
	//intํ˜•์œผ๋กœ 1000๊ณผ ๋น„๊ต.
	if(parseInt(put_bp) < 1000 && put_bp.length != 0)
	{
		alert("1,000(์ฒœ)BP์ด์ƒ์˜ ๊ฐ’์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
		$("#bp_01").val(""); //์ง€์šฐ๊ธฐ
		$("#bp_01").focus(); //ํฌ์ปค์Šค ํ•ด์ฃผ๊ธฐ
		return false; //์‹คํ–‰์ค‘์ง€
	}

	//๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 40% ์ œ์™ธํ•œ ๊ธˆ์•ก
	var minus_bp = (put_bp * 40 / 100);
	
	//์ตœ์ข… ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
	var real_bp = (put_bp - minus_bp);
	
	//์ฟ ํฐ ์„ค์ •๊ฐ’์ด ์žˆ๋Š”์ง€?
	if($("#use_coupon").val())
	{
		//์„ ํƒํ•œ ์ฟ ํฐ%์— ๋”ฐ๋ผ ๊ฒŒ์‚ฐ
		var su_per = (minus_bp * $("#use_coupon").val() / 100);
		
		//์ตœ์ข…๊ธˆ์•ก์— ํ• ์ธ๋˜๋Š”๊ธˆ์•ก ํ•ฉ์น˜๊ธฐ
		real_bp = real_bp + su_per;
		
		//์ฟ ํฐ์œผ๋กœ ํ• ์ธ๋ฐ›๋Š”๊ธˆ์•ก ์ฝค๋งˆ์ฐ๊ธฐ ์ž‘์—…
		var coupon_in = number_format(su_per);

		//ํ• ์ธ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
		$("#coupon_bp").text(coupon_in);

		//ํผ์„ผํŠธ์œจ์— ๋”ฐ๋ฅธ ํ‘œ๊ธฐ
		$("#per").text($("#use_coupon").val());
	}

	// topClass or primium pc ๋‘˜์ค‘ํ•˜๋‚˜๋ผ๋„ Y์ผ๋•Œ
	if($("#top_class:checked").val() == "Y" && $("#primium_pc:checked").val() == "Y")
	{
		// ํƒ‘ํด๋ž˜์Šค๋Š” ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 20% ํ• ์ธ
		var top_class = (minus_bp * 20 / 100);

		// ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์€ ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 30% ํ• ์ธ
		var pc_class = (minus_bp * 30 / 100);
		
		//๋‘˜ ๋‹ค ์ด๊ธฐ๋•Œ๋ฌธ์— ๋‘˜์ด ํ• ์ธํ•œ ๊ธˆ์•ก์„ ํ•ฉ์ณ์ค€๋‹ค.
		var top_pc = parseInt(top_class)+parseInt(pc_class);
		
		//๊ฐœ๋ณ„ ํ• ์ธ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฝค๋งˆ์ฐ๊ธฐ.
		var top_in = number_format(top_pc);
		
		//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก + ํƒ‘ํด๋ž˜์Šค ํ• ์ธ๊ธˆ์•ก ํ•ฉ์‚ฐ
		real_bp = real_bp + top_pc;

		$("#class_bp").text(top_in);
	}
	else
	{
		//ํƒ‘ํด๋ž˜์Šค๋งŒ ์ผ๋•Œ
		if($("#top_class:checked").val() == "Y")
		{
			//ํƒ‘ํด๋ž˜์Šค ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var top_class = (minus_bp * 20 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var top_in = number_format(top_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			real_bp = real_bp + top_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(top_in);
		}
		
		//ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์ผ๋•Œ
		if($("#primium_pc:checked").val() == "Y")
		{
			//ํ”ผ์”จ๋ฐฉ ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var pc_class = (minus_bp * 30 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var pc_in = number_format(pc_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			real_bp = real_bp + pc_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(pc_in);
		}

		//๋‘˜ ๋‹ค N์ผ๋•Œ
		if($("#top_class:checked").val() == "N" && $("#primium_pc:checked").val() == "N")
		{
			//0์œผ๋กœ ํ‘œ๊ธฐ
			$("#class_bp").text(0);
		}
	}

	//์ฝค๋งˆ ์ž‘์—…
	var put_in		= number_format(put_bp);	//์ž…๋ ฅํ•œ ๊ฐ’.
	var minus_in	= number_format(minus_bp);	//์ˆ˜์ˆ˜๋ฃŒ ๊ฐ’.
	var total_in	= number_format(real_bp);	//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก ๊ฐ’.

	//๊ตฌํ•œ ๊ฐ’ ๋„ฃ๊ธฐ
	$("#bp_01").val(put_in);
	$("#default_bp").text(minus_in);
	$("#total_bp").text(total_in);
}

//์ฝค๋งˆ ์ œ๊ฑฐํ•˜๊ธฐ
function comma_less(amount, id)
{
	var set_bp = $("#"+id).val(amount.replace(/,/g, ''));
	return set_bp;
}

//๊ณ„์‚ฐ๋œ BP๊ตฌํ•˜๊ธฐ
function get_bp()
{
	//๊ธฐ๋ณธ ์ˆ˜์ˆ˜๋ฃŒ ๊ฐ’
	var default_bp = $("#bp_01").val().replace(/,/g, '');

	//๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 40% ์ œ์™ธํ•œ ๊ธˆ์•ก
	var minus_bp = (default_bp * 40 / 100);

	//์ตœ์ข… ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
	var real_bp = (default_bp - minus_bp);

	var bp = $("#default_bp").text().replace(/,/g, '');
	var su_per = (bp * $("#use_coupon").val() / 100);
	var re_total = parseInt(real_bp) + parseInt(su_per);

	// topClass or primium pc ๋‘˜์ค‘ํ•˜๋‚˜๋ผ๋„ Y์ผ๋•Œ
	if($("#top_class:checked").val() == "Y" && $("#primium_pc:checked").val() == "Y")
	{
		// ํƒ‘ํด๋ž˜์Šค๋Š” ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 20% ํ• ์ธ
		var top_class = (minus_bp * 20 / 100);

		// ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์€ ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 30% ํ• ์ธ
		var pc_class = (minus_bp * 30 / 100);
		
		//๋‘˜ ๋‹ค ์ด๊ธฐ๋•Œ๋ฌธ์— ๋‘˜์ด ํ• ์ธํ•œ ๊ธˆ์•ก์„ ํ•ฉ์ณ์ค€๋‹ค.
		var top_pc = parseInt(top_class)+parseInt(pc_class);
		
		//๊ฐœ๋ณ„ ํ• ์ธ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฝค๋งˆ์ฐ๊ธฐ.
		var top_in = number_format(top_pc);
		
		//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก + ํƒ‘ํด๋ž˜์Šค ํ• ์ธ๊ธˆ์•ก ํ•ฉ์‚ฐ
		re_total = re_total + top_pc;

		$("#class_bp").text(top_in);
	}
	else
	{
		//ํƒ‘ํด๋ž˜์Šค๋งŒ ์ผ๋•Œ
		if($("#top_class:checked").val() == "Y")
		{
			//ํƒ‘ํด๋ž˜์Šค ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var top_class = (minus_bp * 20 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var top_in = number_format(top_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			re_total = re_total + top_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(top_in);
		}
		
		//ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์ผ๋•Œ
		if($("#primium_pc:checked").val() == "Y")
		{
			//ํ”ผ์”จ๋ฐฉ ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var pc_class = (minus_bp * 30 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var pc_in = number_format(pc_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			re_total = re_total + pc_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(pc_in);
		}
		
		//๋‘˜ ๋‹ค N์ผ๋•Œ
		if($("#top_class:checked").val() == "N" && $("#primium_pc:checked").val() == "N")
		{
			//0์œผ๋กœ ํ‘œ๊ธฐ
			$("#class_bp").text(0);
		}
	}

	//์ฟ ํฐ์ˆ˜์ˆ˜๋ฃŒ ํ• ์ธ๊ธˆ์•ก ์„ค์ •
	var coupon_in = number_format(su_per);
	
	//์ตœ์ข…๊ธˆ์•ก ์žฌ ์„ค์ •
	var re_total_in = number_format(re_total);
	
	//์ฟ ํฐ ์ฐจ๊ฐ๊ธˆ์•ก ๋„ฃ๊ธฐ
	$("#coupon_bp").text(coupon_in);
	
	//์ตœ์ข…๊ธˆ์•ก ๋„ฃ๊ธฐ
	$("#total_bp").text(re_total_in);

	//์ฟ ํฐํ• ์ธ์œจ ๋„ฃ๊ธฐ
	$("#per").text($("#use_coupon").val());
}

</script>
<body>
	<div class="bp_layer">
		<b>ํŒ๋งค ์˜ˆ์ •๊ธˆ์•ก</b>
		<input type="text" name="bp_01" id="bp_01" onkeydown="return isNum();" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');" onblur="get_data(this.value);" onfocus="comma_less(this.value, 'bp_01')" maxlength="15"><b> BP</b>
		<select id="use_coupon" onchange="get_bp();">
			<option value="">์ฟ ํฐ ์„ ํƒ</option>
			<option value="5">5%</option>
			<option value="10">10%</option>
			<option value="15">15%</option>
			<option value="20">20%</option>
			<option value="25">25%</option>
			<option value="30">30%</option>
			<option value="35">35%</option>
			<option value="40">40%</option>
			<option value="45">45%</option>
			<option value="50">50%</option>
		</select>
	</div>
	<br>
	<div>
		<b>TOP CLASS ๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 20% ํ• ์ธ</b>
		<span>๋ณด์œ </span><input type="radio" id="top_class" name="top_class" value="Y" onchange="get_bp();">
		<span>๋ฏธ๋ณด์œ </span><input type="radio" id="top_class" name="top_class" value="N" onchange="get_bp();" checked>
		<br>
		<br>
		<b>ํ”„๋ฆฌ๋ฏธ์—„ PC๋ฐฉ ๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 30% ํ• ์ธ</b>
		<span>์‚ฌ์šฉ</span><input type="radio" id="primium_pc" name="primium_pc" value="Y" onchange="get_bp();">
		<span>๋ฏธ์‚ฌ์šฉ</span><input type="radio" id="primium_pc" name="primium_pc" value="N" onchange="get_bp();" checked>
	</div>
	<br>
	<div>
		<b>๊ธฐ๋ณธ ์ˆ˜์ˆ˜๋ฃŒ (40%)</b> : -<b id="default_bp">0</b><b> BP</b>
		<br>
		<br>
		<b>์ˆ˜์ˆ˜๋ฃŒ ํ• ์ธ ๊ธˆ์•ก (์ด </b><b id="per">0</b> <b>% ํ• ์ธ)</b> : <b id="coupon_bp">0</b><b> BP</b>
		<br>
		<br>
		<b>๊ฐœ๋ณ„ ํ• ์ธ ๊ธˆ์•ก</b> : <b id="class_bp">0</b><b> BP</b>
		<br>
		<br>
		<b>์ตœ์ข… ๋ฐ›๋Š” ๊ธˆ์•ก</b> : <b id="total_bp">0</b><b> BP</b>
	</div>
</body>
</html>

 

 

์ค‘์š”ํ–ˆ๋˜ ๋ถ€๋ถ„

 

์•„๋งˆ๋„ ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์•„์˜ค๋Š” 

<b>ํŒ๋งค ์˜ˆ์ •๊ธˆ์•ก</b>
<input type="text" name="bp_01" id="bp_01" onkeydown="return isNum();" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');" onblur="get_data(this.value);" onfocus="comma_less(this.value, 'bp_01')" maxlength="15"><b> BP</b>

 

์ด ๋ถ€๋ถ„์ด ์ œ์ผ ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”.

 

์ด์œ ๋Š” input ํƒœ๊ทธ์— ์ด๋ฒคํŠธ๋ฅผ ๊ต‰์žฅํžˆ ๋งŽ์ด ๊ฑธ์–ด ๋‘” ์ด์œ ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ฒซ์งธ๋Š” ํ•œ๊ธ€, ์˜๋ฌธ์ด ์ž…๋ ฅ์ด ๋˜๋ฉด ์•ˆ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— 

 

์˜๋ฌธ์€ onkeydown ์ด๋ฒคํŠธ๋ฅผ ๊ฑธ์–ด ์•„๋ž˜์˜ ํ•จ์ˆ˜๋ฅผ ํƒ€๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

//input์— ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›๊ธฐ
function isNum()
{
	if ((event.keyCode >= 45 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8|| event.keyCode==13 || event.keyCode==9) return true;
	else return false;
}

 

ํ‚ค๊ฐ€ ๋ˆŒ๋ ธ์„ ๋•Œ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” input ํƒœ๊ทธ์˜ ์ด๋ฒคํŠธ ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ ํ•ด๋‹น ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ž…๋ ฅ์ด ์•ˆ๋˜๊ฒŒ ์ฒ˜๋ฆฌํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 

 

์†”์งํžˆ ์ด๊ฑด ์—†์–ด๋„ ์ƒ๊ด€์—†์Šต๋‹ˆ๋‹ค.

 

์ •๊ทœ์‹์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์ฃ .

onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"

 

์ด ๋ถ€๋ถ„์„ ๋ณด์‹œ๋ฉด ํ‚ค๋ฅผ ๋ˆŒ๋ €๋‹ค ๋–ผ์—ˆ์„ ๋•Œ  0~9 ๊ฐ’๋งŒ ๋ฐ›๊ณ  ๋‚˜๋จธ์ง„ ๋‹ค ๋นˆ ๊ฐ’์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ์˜๋ฌธ, ํ•œ๊ธ€ ์ „๋ถ€ ๋‹ค ํŠ•๊ฒจ ๋‚ผ ์ˆ˜ ์žˆ๋˜ ๊ฑฐ์ฃ .

 

 

์œ„์™€ ๊ฐ™์ด ํ‚ค๊ฐ€ ์˜ฌ๋ผ์˜ฌ ๋•Œ ์ด๋ฒคํŠธ๋ฅผ ๊ฑธ์–ด ๋นˆ ๊ฐ’์ด ๋˜๊ฒŒ๋” ์ฒ˜๋ฆฌํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ˆซ์ž๋Š” ์ž…๋ ฅ๋ฐ›๊ณ  ๋‚˜๋จธ์ง„ ๋นˆ ๊ฐ’์œผ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  onblur ์ด๋ฒคํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธํ’‹ ์ฐฝ์—์„œ ๋‚˜๊ฐ”์„ ๋•Œ ๋˜๋Š” ํฌ์ปค์‹ฑ์ด ํ•ด์ œ๋˜์—ˆ์„ ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ํ•จ์ˆ˜๋กœ

 

ํฌ์ปค์‹ฑ ์ „๊นŒ์ง€์˜ ์ž…๋ ฅ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ๊ฐ’์„ ๊ตฌํ•ด์˜ค๋Š” ํ•จ์ˆ˜๋ฅผ ํƒœ์› ์Šต๋‹ˆ๋‹ค.

 

get_data()๋ผ๋Š” ํ•จ์ˆ˜์ฃ .

 

๊ฐ„๋‹จํžˆ ๋ณด์—ฌ๋“œ๋ฆฌ๋ฉด

์ด๋ ‡๊ฒŒ ์ธํ’‹ ์ฐฝ์ด ๋น„ํ™œ์„ฑํ™”๋  ๋•Œ ์ฝค๋งˆ ์ฐ์–ด์ฃผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด๋ฒคํŠธ์— ๊ฑธ์–ด๋‘” ๊ฒ๋‹ˆ๋‹ค.

 

๋”๋ณด๊ธฐ
//๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
function get_data(double) 
{
	//์ž…๋ ฅ ๊ฐ€๊ฒฉ
	var put_bp = double.toString();
	
	//intํ˜•์œผ๋กœ 1000๊ณผ ๋น„๊ต.
	if(parseInt(put_bp) < 1000 && put_bp.length != 0)
	{
		alert("1,000(์ฒœ)BP์ด์ƒ์˜ ๊ฐ’์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
		$("#bp_01").val(""); //์ง€์šฐ๊ธฐ
		$("#bp_01").focus(); //ํฌ์ปค์Šค ํ•ด์ฃผ๊ธฐ
		return false; //์‹คํ–‰์ค‘์ง€
	}

	//๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 40% ์ œ์™ธํ•œ ๊ธˆ์•ก
	var minus_bp = (put_bp * 40 / 100);
	
	//์ตœ์ข… ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
	var real_bp = (put_bp - minus_bp);
	
	//์ฟ ํฐ ์„ค์ •๊ฐ’์ด ์žˆ๋Š”์ง€?
	if($("#use_coupon").val())
	{
		//์„ ํƒํ•œ ์ฟ ํฐ%์— ๋”ฐ๋ผ ๊ฒŒ์‚ฐ
		var su_per = (minus_bp * $("#use_coupon").val() / 100);
		
		//์ตœ์ข…๊ธˆ์•ก์— ํ• ์ธ๋˜๋Š”๊ธˆ์•ก ํ•ฉ์น˜๊ธฐ
		real_bp = real_bp + su_per;
		
		//์ฟ ํฐ์œผ๋กœ ํ• ์ธ๋ฐ›๋Š”๊ธˆ์•ก ์ฝค๋งˆ์ฐ๊ธฐ ์ž‘์—…
		var coupon_in = number_format(su_per);

		//ํ• ์ธ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
		$("#coupon_bp").text(coupon_in);

		//ํผ์„ผํŠธ์œจ์— ๋”ฐ๋ฅธ ํ‘œ๊ธฐ
		$("#per").text($("#use_coupon").val());
	}

	// topClass or primium pc ๋‘˜์ค‘ํ•˜๋‚˜๋ผ๋„ Y์ผ๋•Œ
	if($("#top_class:checked").val() == "Y" && $("#primium_pc:checked").val() == "Y")
	{
		// ํƒ‘ํด๋ž˜์Šค๋Š” ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 20% ํ• ์ธ
		var top_class = (minus_bp * 20 / 100);

		// ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์€ ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 30% ํ• ์ธ
		var pc_class = (minus_bp * 30 / 100);
		
		//๋‘˜ ๋‹ค ์ด๊ธฐ๋•Œ๋ฌธ์— ๋‘˜์ด ํ• ์ธํ•œ ๊ธˆ์•ก์„ ํ•ฉ์ณ์ค€๋‹ค.
		var top_pc = parseInt(top_class)+parseInt(pc_class);
		
		//๊ฐœ๋ณ„ ํ• ์ธ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฝค๋งˆ์ฐ๊ธฐ.
		var top_in = number_format(top_pc);
		
		//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก + ํƒ‘ํด๋ž˜์Šค ํ• ์ธ๊ธˆ์•ก ํ•ฉ์‚ฐ
		real_bp = real_bp + top_pc;

		$("#class_bp").text(top_in);
	}
	else
	{
		//ํƒ‘ํด๋ž˜์Šค๋งŒ ์ผ๋•Œ
		if($("#top_class:checked").val() == "Y")
		{
			//ํƒ‘ํด๋ž˜์Šค ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var top_class = (minus_bp * 20 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var top_in = number_format(top_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			real_bp = real_bp + top_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(top_in);
		}
		
		//ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์ผ๋•Œ
		if($("#primium_pc:checked").val() == "Y")
		{
			//ํ”ผ์”จ๋ฐฉ ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var pc_class = (minus_bp * 30 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var pc_in = number_format(pc_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			real_bp = real_bp + pc_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(pc_in);
		}

		//๋‘˜ ๋‹ค N์ผ๋•Œ
		if($("#top_class:checked").val() == "N" && $("#primium_pc:checked").val() == "N")
		{
			//0์œผ๋กœ ํ‘œ๊ธฐ
			$("#class_bp").text(0);
		}
	}

	//์ฝค๋งˆ ์ž‘์—…
	var put_in		= number_format(put_bp);	//์ž…๋ ฅํ•œ ๊ฐ’.
	var minus_in	= number_format(minus_bp);	//์ˆ˜์ˆ˜๋ฃŒ ๊ฐ’.
	var total_in	= number_format(real_bp);	//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก ๊ฐ’.

	//๊ตฌํ•œ ๊ฐ’ ๋„ฃ๊ธฐ
	$("#bp_01").val(put_in);
	$("#default_bp").text(minus_in);
	$("#total_bp").text(total_in);
}

 

๋˜ ํฌ์ปค์‹ฑ(input ํ™œ์„ฑํ™”)์ด ๋˜์—ˆ์„ ๋•Œ ์ฝค๋งˆ๋ฅผ ์ฐ์–ด์คฌ๋˜ ๋ถ€๋ถ„์„ ๋‹ค์‹œ ์ฝค๋งˆ๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ๊ฐ’์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๊ฒŒ๋” onfocus ์ด๋ฒคํŠธ๋ฅผ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

์œ„์™€ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์œ„์— ์‚ฌ์šฉ๋œ ํ•จ์ˆ˜๋Š” ์•„๋ž˜์— ์ ‘์€ ๊ธ€๋กœ ์ฒจ๋ถ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๋”๋ณด๊ธฐ
//์ฝค๋งˆ ์ œ๊ฑฐํ•˜๊ธฐ
function comma_less(amount, id)
{
	var set_bp = $("#"+id).val(amount.replace(/,/g, ''));
	return set_bp;
}

 

๋˜ ์ฟ ํฐ ์„ ํƒํ•  ๋•Œ์— ๊ฐ’์ด ๋ฐ”๋€Œ๊ฒŒ ์„ค์ •ํ•œ ๊ฑด ๋ฐ”๋กœ onchange ์ด๋ฒคํŠธ๋ฅผ ๊ฑธ์–ด์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

 

<select id="use_coupon" onchange="get_bp();">
    <option value="">์ฟ ํฐ ์„ ํƒ</option>
    <option value="5">5%</option>
    <option value="10">10%</option>
    <option value="15">15%</option>
    <option value="20">20%</option>
    <option value="25">25%</option>
    <option value="30">30%</option>
    <option value="35">35%</option>
    <option value="40">40%</option>
    <option value="45">45%</option>
    <option value="50">50%</option>
</select>

 

์œ„์— ๋ณด์‹œ๋ฉด select ํƒœ๊ทธ์— onchange ์ด๋ฒคํŠธ๋ฅผ ๊ฑธ์–ด get_bp()๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

์•„๋ž˜๋Š” get_bp() ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.

 

๋”๋ณด๊ธฐ
//๊ณ„์‚ฐ๋œ BP๊ตฌํ•˜๊ธฐ
function get_bp()
{
	//๊ธฐ๋ณธ ์ˆ˜์ˆ˜๋ฃŒ ๊ฐ’
	var default_bp = $("#bp_01").val().replace(/,/g, '');

	//๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 40% ์ œ์™ธํ•œ ๊ธˆ์•ก
	var minus_bp = (default_bp * 40 / 100);

	//์ตœ์ข… ๋ฐ›๋Š”๊ธˆ์•ก ๋„ฃ์–ด์ฃผ๊ธฐ
	var real_bp = (default_bp - minus_bp);

	var bp = $("#default_bp").text().replace(/,/g, '');
	var su_per = (bp * $("#use_coupon").val() / 100);
	var re_total = parseInt(real_bp) + parseInt(su_per);

	// topClass or primium pc ๋‘˜์ค‘ํ•˜๋‚˜๋ผ๋„ Y์ผ๋•Œ
	if($("#top_class:checked").val() == "Y" && $("#primium_pc:checked").val() == "Y")
	{
		// ํƒ‘ํด๋ž˜์Šค๋Š” ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 20% ํ• ์ธ
		var top_class = (minus_bp * 20 / 100);

		// ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์€ ์ˆ˜์ˆ˜๋ฃŒ ๋Œ€๋น„ 30% ํ• ์ธ
		var pc_class = (minus_bp * 30 / 100);
		
		//๋‘˜ ๋‹ค ์ด๊ธฐ๋•Œ๋ฌธ์— ๋‘˜์ด ํ• ์ธํ•œ ๊ธˆ์•ก์„ ํ•ฉ์ณ์ค€๋‹ค.
		var top_pc = parseInt(top_class)+parseInt(pc_class);
		
		//๊ฐœ๋ณ„ ํ• ์ธ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฝค๋งˆ์ฐ๊ธฐ.
		var top_in = number_format(top_pc);
		
		//์ตœ์ข… ๋ฐ›์„๊ธˆ์•ก + ํƒ‘ํด๋ž˜์Šค ํ• ์ธ๊ธˆ์•ก ํ•ฉ์‚ฐ
		re_total = re_total + top_pc;

		$("#class_bp").text(top_in);
	}
	else
	{
		//ํƒ‘ํด๋ž˜์Šค๋งŒ ์ผ๋•Œ
		if($("#top_class:checked").val() == "Y")
		{
			//ํƒ‘ํด๋ž˜์Šค ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var top_class = (minus_bp * 20 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var top_in = number_format(top_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			re_total = re_total + top_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(top_in);
		}
		
		//ํ”„๋ฆฌ๋ฏธ์—„ pc๋ฐฉ์ผ๋•Œ
		if($("#primium_pc:checked").val() == "Y")
		{
			//ํ”ผ์”จ๋ฐฉ ํผ์„ผํŠธ์œจ ๊ณ„์‚ฐ
			var pc_class = (minus_bp * 30 / 100);

			//์ฝค๋งˆ ์ฐ๊ธฐ
			var pc_in = number_format(pc_class);

			//๋ฐ›์„๊ธˆ์•ก + ํ• ์ธ๋ฐ›์€๊ธˆ์•ก ํ•ฉ์‚ฐ
			re_total = re_total + pc_class;

			//๊ฐœ๋ณ„ํ• ์ธ๊ธˆ์•ก์— ํ‘œ๊ธฐ
			$("#class_bp").text(pc_in);
		}
		
		//๋‘˜ ๋‹ค N์ผ๋•Œ
		if($("#top_class:checked").val() == "N" && $("#primium_pc:checked").val() == "N")
		{
			//0์œผ๋กœ ํ‘œ๊ธฐ
			$("#class_bp").text(0);
		}
	}

	//์ฟ ํฐ์ˆ˜์ˆ˜๋ฃŒ ํ• ์ธ๊ธˆ์•ก ์„ค์ •
	var coupon_in = number_format(su_per);
	
	//์ตœ์ข…๊ธˆ์•ก ์žฌ ์„ค์ •
	var re_total_in = number_format(re_total);
	
	//์ฟ ํฐ ์ฐจ๊ฐ๊ธˆ์•ก ๋„ฃ๊ธฐ
	$("#coupon_bp").text(coupon_in);
	
	//์ตœ์ข…๊ธˆ์•ก ๋„ฃ๊ธฐ
	$("#total_bp").text(re_total_in);

	//์ฟ ํฐํ• ์ธ์œจ ๋„ฃ๊ธฐ
	$("#per").text($("#use_coupon").val());
}

 

์ฟ ํฐ ๊ฐ’๊ณผ radio ๊ฐ’์„ ๊ณ„์‚ฐํ•ด์ฃผ๋Š” ํ•จ์ˆ˜์ธ๋ฐ radio์—์„œ๋„ ๊ฐ™์ด ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ถ€๋ถ„์˜ onchange ์ด๋ฒคํŠธ๋„ get_bp()๋กœ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

 

<div>
    <b>TOP CLASS ๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 20% ํ• ์ธ</b>
    <span>๋ณด์œ </span><input type="radio" id="top_class" name="top_class" value="Y" onchange="get_bp();">
    <span>๋ฏธ๋ณด์œ </span><input type="radio" id="top_class" name="top_class" value="N" onchange="get_bp();" checked>
    <br>
    <br>
    <b>ํ”„๋ฆฌ๋ฏธ์—„ PC๋ฐฉ ๊ธฐ๋ณธ์ˆ˜์ˆ˜๋ฃŒ 30% ํ• ์ธ</b>
    <span>์‚ฌ์šฉ</span><input type="radio" id="primium_pc" name="primium_pc" value="Y" onchange="get_bp();">
    <span>๋ฏธ์‚ฌ์šฉ</span><input type="radio" id="primium_pc" name="primium_pc" value="N" onchange="get_bp();" checked>
</div>

 

ํ•ด๋‹น onchange ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์‹œ์ ์€ radio์˜ value๊ฐ’์ด ๋‹ฌ๋ผ์กŒ์„ ๋•Œ์ž…๋‹ˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ํด๋ฆญ ์‹œ๋งˆ๋‹ค ๋ณ€๊ฒฝ๋˜๋Š” ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ๊ณ„์†ํ•ด์„œ ๊ฐ’์„ ๋‹ค์‹œ ๊ฐ€์ ธ์˜ค๋Š” ํŒจํ„ด์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ๊นŒ์ง€ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๊ฐ€ ๋์ธ ๊ฑฐ ๊ฐ™๋„ค์š” ใ…Žใ…Ž ๋” ๊ถ๊ธˆํ•˜์‹ ์  ์žˆ์œผ์‹œ๋ฉด ๋Œ“๊ธ€๋กœ ๋‚จ๊ฒจ์ฃผ์„ธ์š” ใ…Žใ…Ž

 

์•„์ง ๋งŽ์ด ๋ถ€์กฑํ•˜๊ณ  ๋ณด์™„ํ•ด์•ผ ํ•  ๋ถ€๋ถ„๋„ ์žˆ์ง€๋งŒ ์ ์ฐจ ์ด๋ ‡๊ฒŒ ์‹œ๋„ํ•˜๋‹ค ๋ณด๋ฉด ์–ธ์  ๊ฐ„ ๊ดœ์ฐฎ์•„์ง€๊ฒ ์ฃ ??

 

 

๋งŒ๋“ค๋ฉด์„œ ํž˜๋“ค์—ˆ๋˜ ์ 

 

ํž˜๋“  ๊ฑด ๋”ฑํžˆ ์—†์ง€๋งŒ ์ตœ๋Œ€ํ•œ ๋น„์Šทํ•˜๊ฒŒ ๋งŒ๋“œ๋ ค๊ณ  ํ–ˆ๋˜ ๊ฑฐ ๊ฐ™์•„์š” ใ…Žใ…Ž

 

 

ํ•˜๊ณ  ์‹ถ์€ ๋ง

 

์ƒ๊ฐ์ด ๋“ค ๋•Œ ์‹คํ–‰์œผ๋กœ ์˜ฎ๊ธฐ๋Š” ๊ฒŒ ์ข‹์€ ๋ถ€๋ถ„์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

์—ฐ์Šต์ด ๋ชฉ์ ์ด๋ผ๋ฉด ์ด๋ ‡๊ฒŒ ํ•˜๋‚˜๋ฅผ ๋‘๊ณ  ๋”ฐ๋ผ ํ•ด ๋ณด์‹œ๊ณ  ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๋„ ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•์ด๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

 

๋ถ€์กฑํ•จ์ด ๋งŽ์€ ๊ธ€ ๋๊นŒ์ง€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€