๊ด€๋ฆฌ ๋ฉ”๋‰ด

bom's happy life

[JS] ๋™์ ํ…Œ์ด๋ธ” ํƒœ๊ทธ๋ฅผ " "๊ฐ€ ์•„๋‹Œ ``๋ฐฑํ‹ฑ์œผ๋กœ ํ•ด์ฃผ๋Š” ์ด์œ ? ๋ณธ๋ฌธ

Deveolpment Study๐Ÿ—‚๏ธ/Javascript

[JS] ๋™์ ํ…Œ์ด๋ธ” ํƒœ๊ทธ๋ฅผ " "๊ฐ€ ์•„๋‹Œ ``๋ฐฑํ‹ฑ์œผ๋กœ ํ•ด์ฃผ๋Š” ์ด์œ ?

bompeach 2023. 5. 26. 16:20

` ` ๋ฐฑํ‹ฑ์„ ์‚ฌ์šฉํ•ด์ฃผ๋Š” ์ด์œ ๋Š”?

 

td ์•ˆ์— styleํƒœ๊ทธ๋ฅผ ์ฃผ๊ณ  ์‹ถ์€๋ฐ tdํƒœ๊ทธ์˜ " " ์Œ๋”ฐ์˜ดํ‘œ์™€ styleํƒœ๊ทธ์˜ ์Œ๋”ฐ์˜ดํ‘œ๊ฐ€ ๊ฒน์ณ์„œ ์ธ์‹์ด ์•ˆ๋œ๋‹ค.

์ด๋Ÿฐ ๊ฒฝ์šฐ์— ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•ด์ค˜์•ผ ํ•˜๋Š”๋ฐ ๋ฒˆ๊ฑฐ๋กœ์›Œ์ง€๊ณ  ๊ฐ€๋…์„ฑ๋„ ์ข‹์ง€ ๋ชปํ•˜๊ฒŒ ๋œ๋‹ค. 

๊ทธ๋ž˜์„œ ` ` ๋ฐฑํ‹ฑ์œผ๋กœ ๋ฌถ์–ด์ฃผ๊ณ  style ํƒœ๊ทธ๋Š” " "๋กœ ๊ทธ๋Œ€๋กœ ํ‘œํ˜„ํ•ด์ค€๋‹ค!

(์•ˆ์—๋‹ค style ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ๊ตณ์ด ๋ฐฑํ‹ฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋ฌด๋ฐฉํ•˜๋‹ค.)

 

์‚ฌ์šฉ์˜ˆ์‹œ!

$.ajax({
	url : "/reservation.do",
	type : 'post',
	data : { "placeRentLogSeq": placeRentLogSeq },
	dataType : "json",
	success : function(data) {
					
	//alert(rentDate);
	console.log("placeRentLogSeq : ", placeRentLogSeq);
	console.log("data : ", data);
	console.log("data : ", data[0].rentDate);
					
	var rentList = "";
	var rentDate = data[0].rentDate;
	var rent1 = data[0].rent1;
	var rent2 = data[0].rent2;
	var rent3 = data[0].rent3;
				    
	rentList += `<tr>`;
	rentList += `<td class="rentDate">\${rentDate}</td>`;
	rentList += `<td></td>`;
	rentList += `<td></td>`;
	rentList += `</tr>`;
					
    rentList += `<tr>`;
    rentList += `<td class="rentTimes">1ํƒ€์ž„(10:00~12:00)</td>`;
    rentList += `<td class="rentCnt">\${rent1}/15</td>`;
    if(rent1 < 15) {
        rentList += `<td class="padding-bottom"><a class="reservYBtn" href="javascript:placeRentAdd('\${rentDate}','1')">์˜ˆ์•ฝ๊ฐ€๋Šฅ</a></td>`;
    } else {
        rentList += `<td class="padding-bottom"><a class="reservNBtn">์˜ˆ์•ฝ๋ถˆ๊ฐ€</a></td>`;
    }
    rentList += `</tr>`;

    rentList += `<tr>`;
    rentList += `<td class="rentTimes">2ํƒ€์ž„(13:00~15:00)</td>`;
    rentList += `<td class="rentCnt">\${rent2}/15</td>`;
    if(rent2 < 15) {
        rentList += `<td class="padding-bottom"><a class="reservYBtn" href="javascript:placeRentAdd('\${rentDate}','2')">์˜ˆ์•ฝ๊ฐ€๋Šฅ</a></td>`;
    } else {
        rentList += `<td class="padding-bottom"><a class="reservNBtn">์˜ˆ์•ฝ๋ถˆ๊ฐ€</a></td>`;
    }
    rentList += `</tr>`;

    $(".modal_tbl").html(rentList);
    },
        error : function() {
            alert("error");
        },
});

 

์„ค๋ช…์„ ๋”ํ•˜์ž๋ฉด : 

 

์œ„์˜ ์ฝ”๋“œ์—์„œ ๋ฐฑํ‹ฑ(``)์„ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” ES6๋ถ€ํ„ฐ ๋„์ž…๋œ Template Literal ๋ฌธ๋ฒ•์„ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ์ด๋‹ค. Template Literal์€ ๋ฌธ์ž์—ด์„ ๋‹ค๋ฃจ๋Š” ์ƒˆ๋กœ์šด ๋ฐฉ์‹์œผ๋กœ, ๋ฌธ์ž์—ด ๋‚ด์— ๋ณ€์ˆ˜๋‚˜ ํ‘œํ˜„์‹์„ ์‰ฝ๊ฒŒ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

๋ฐฑํ‹ฑ(` `)์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด ๋‚ด์—์„œ ${ }๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ€์ˆ˜๋‚˜ ํ‘œํ˜„์‹์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ๋‹ค. 

๋˜ํ•œ, ๋ฌธ์ž์—ด ๋‚ด์— ํฐ๋”ฐ์˜ดํ‘œ๋‚˜ ์ž‘์€๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•  ๋•Œ ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋˜๋ฏ€๋กœ ํŽธ๋ฆฌํ•˜๋‹ค. ๋”ฐ๋ผ์„œ, ๋ฐฑํ‹ฑ๊ณผ Template Literal์„ ์‚ฌ์šฉํ•˜์—ฌ ๋™์ ์ธ ๋ฌธ์ž์—ด์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋”ฐ๋ผ์„œ, ๋ฐฑํ‹ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋™์ ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๋ฉด ๋‹ค์ค‘ ์ค„ ๋ฌธ์ž์—ด๊ณผ ๋ณ€์ˆ˜ ์‚ฝ์ž…, ํ‘œํ˜„์‹ ํ˜•๊ฐ€ ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ๊ณผ ์œ ์—ฐ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 

1. ๋‹ค์ค‘ ์ค„ ๋ฌธ์ž์—ด 

const multiLineString = `์ด๊ฒƒ์€
์—ฌ๋Ÿฌ ์ค„์˜
๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.`;

2. ๋ณ€์ˆ˜ ์‚ฝ์ž…

const name = "Alice";
const greeting = `์•ˆ๋…•ํ•˜์„ธ์š”, ${name}๋‹˜!`;

3. ํ‘œํ˜„์‹์‚ฌ์šฉ

const num1 = 10;
const num2 = 5;
const result = `๋‘ ์ˆ˜์˜ ํ•ฉ์€ ${num1 + num2}์ž…๋‹ˆ๋‹ค.`;

 

์œ„์˜ ์„ธ๊ฐ€์ง€ ์ƒํ™ฉ ์‹œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.