728x90
๋ฌธ์ ํ์ด์ ํ์ํ ์ด๋ฏธ์ง Download
๋ฌธ์ 1 -
๋ฌธ์ ํ์ด ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>Life on the water</h1>
<img alt="" src="./images/photo1.jpg" class="photo">
<img alt="" src="./images/photo2.jpg" class="photo">
<br>
<img alt="" src="./images/photo3.jpg" class="photo">
<img alt="" src="./images/photo4.jpg" class="photo">
<script type="text/javascript">
$(document).ready(function() {
/*
$(".photo").click(function() {
});
*/
$(".photo").on("click", function () {
$(this).css("border", "solid 5px #ff0000");
});
});
</script>
</body>
</html>
๋ฌธ์ 2 -
๋ฌธ์ ํ์ด ->
HTML ํ์ผ
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>์ก๋ถ ์ ๋ณด์ ์
๋ ฅ</h1>
<form id="sendFrm">
์ด๋ฆ: <input type="text" name="name" id="_name" size="20">
<br><br>
์ฐํธ๋ฒํธ: <input type="text" name="postNum1" id="_postNum1" size="10" maxlength="3">-<input type="text" name="postNum2" id="_postNum2" size="10" maxlength="4">
<button type="button">์ฃผ์๋ณํ</button>
<br><br>
์ฃผ์: <textarea rows="2" cols="50" id="_address" name="address"></textarea>
<br><br>
๋ฐฐ๋ฌ์๊ฐ:
<select name="trans" id="_trans" multiple="multiple">
<option value="10">10:00 ~ 12:00</option>
<option value="12">12:00 ~ 15:00</option>
<option value="15" selected>15:00 ~ 17:00</option>
<option value="17">17:00 ~ 20:00</option>
<option value="0">์ง์ ํ์ง ์์</option>
</select>
<br><br>
์์์ฆ ์์ฒญ:<input type="checkbox" name="money" id="_money"> <!-- on -->
<br><br>
๋งค๊ฑฐ์ง ์์ :
<input type="radio" name="maga" id="_maga" value="์ ์ฒญ" checked="checked">์ ์ฒญ
<input type="radio" name="maga" id="_maga" value="์ ์ฒญํ์ง ์์">์ ์ฒญํ์ง ์์
<br><br>
<button type="button" id="btn">์ ์ก</button>
</form>
<script type="text/javascript">
$(function () {
$("*").focus(function () {
$(this).css("background-color", "green");
});
$("*").blur(function () {
$(this).css("background-color", "#ffffff");
});
$("#btn").click(function () {
// ๋น์นธ ์ฒตํฌ
if( $("#_name").val() == "" ){
alert('์ด๋ฆ์ ๊ธฐ์
ํด ์ฃผ์ญ์์ค');
}
else{
/*
location.href = "NewFile.jsp?"
let name = $("#_name").val();
alert(name);
let postNum1 = $("#_postNum1").val();
alert(postNum1);
let postNum2 = $("#_postNum2").val();
alert(postNum2);
let address = $("#_address").val();
alert(address);
let trans = $("#_trans").val();
alert(trans);
let money = $("#_money").val();
alert(money);
let maga = $("#_maga").val();
alert(maga);
*/
// location.href = "NewFile.jsp?name=" + $("#_name").val()
// $("#sendFrm").attr("action", "NewFile.jsp").submit();
$("#sendFrm").attr("action", "NewFile.jsp");
$("#sendFrm").attr("target", "_blank");
$("#sendFrm").submit(); // ์ค์ ์ด๋
}
});
});
</script>
</body>
</html>
JSP ํ์ผ
๋๋ณด๊ธฐ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String name = request.getParameter("name");
String postNum1 = request.getParameter("postNum1");
String postNum2 = request.getParameter("postNum2");
String address = request.getParameter("address");
String trans[] = request.getParameterValues("trans");
String money = request.getParameter("money");
String maga = request.getParameter("maga");
%>
<%
out.println(name + "<br>");
out.println(postNum1 + "<br>");
out.println(postNum2 + "<br>");
out.println(address + "<br>");
if(trans != null && trans.length > 0){
for(int i = 0;i < trans.length; i++){
out.println(trans[i] + "<br>");
}
}
out.println(money + "<br>");
out.println(maga + "<br>");
%>
๋ฌธ์ 3 -
๋ฌธ์ ํ์ด ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>room image</h1>
<img alt="" src="./images/photo_a.jpg" id="pic">
<script type="text/javascript">
$(function () {
/*
let num = 0;
$("#pic").click(function () {
if(num == 0){
$(this).attr("src", "./images/photo_b.jpg");
num = 1;
}
else{
$(this).attr("src", "./images/photo_a.jpg");
num = 0;
}
});
*/
$("#pic").hover(
function () { // mouseover
$(this).attr("src", "./images/photo_b.jpg");
},
function () { // mouseout
$(this).attr("src", "./images/photo_a.jpg");
}
);
});
</script>
</body>
</html>
๋ฌธ์ 4 -
๋ฌธ์ ํ์ด->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>์ฌ์ง๋ค</h1>
<img alt="" src="images/img01.jpg" picname="์ฑ ์๋น์๋ฅด ์ฑ๋น(์ธ๊ด)">
<img alt="" src="images/img02.jpg" picname="์ฑ ์๋น์๋ฅด ์ฑ๋น(๋ด๊ด)">
<img alt="" src="images/img03.jpg" picname="๋ก์ ๊ฑด๋ฌผ">
<img alt="" src="images/img04.jpg" picname="๊ฐ๋ก๋ฑ">
<script type="text/javascript">
$(document).ready(function() {
$("img").click(function() {
let picname = $(this).attr('picname');
alert(picname);
});
});
</script>
</body>
</html>
๋ฌธ์ 5 -
๋ฌธ์ 6 - ์ฐ๊ณ
๋ฌธ์ ํ์ด->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>์ด๋ฏธ์ง ์๋ ์ฝ์
</h1>
<div class="pic">
</div>
<script type="text/javascript">
$(function () {
for(i = 1;i < 10; i++){ // 1 ~ 9
// let img = $("<img></img>").attr("src", "images/photo_" + i + ".jpg").attr("class", "photo");
let img = $("<img></img>").attr({
"src":"images/photo_" + i + ".jpg",
"class": "photo"
});
// let img = "<img src='images/photo_" + i + ".jpg'></img>";
$(".pic").append(img);
}
$(".photo").click(function () {
$(this).remove();
});
});
</script>
</body>
</html>
๋๊ธ