js ๋จ
<script>
$(function(){
//์ด๋ฒคํธ click, dbclick, keypress(keydown, keyup), on
$("#alertButton").click(function() {
alert("click");
});
//1. ๊ฒ์๋ฒํผ ํด๋ฆญ์ select๊ฐ, text ํ๊ทธ์ ๊ฐ์ console.log ์ถ๋ ฅ
$("#searchBTN").click(function() {
var sel = $("#searchSel").val();
var txt = $("#searchText").val();
console.log(sel, "", txt);
});
//2. searchText ํ๊ทธ์ ์ํฐ ์
๋ ฅ์, select๊ฐ, text ํ๊ทธ์ ๊ฐ์ console.log ์ถ๋ ฅ
//keyup, keydown ํผ ์ ํจ์ฑ ๊ฒ์ฌํ ๋ ์์ฃผ ์ฌ์ฉ
$("#searchText").keypress(function(evt) {
var key = evt.keyCode;
if(key == 13) {
var sel = $("#searchSel").val();
var txt = $("#searchText").val();
console.log(sel, "", txt);
}
});
$("#beforeButton").click(function() {
var textTag = "<input type='text' value='์ด์ ' />";
$("#addLayer").before(textTag);
});
$("#afterButton").click(function() {
var textTag = "<input type='text' value='์ดํ' />";
$("#addLayer").after(textTag);
});
$("#addBtn").click(function() {
var textTag = "<input type='button' class='alertbutton' value='ํด๋ฆญ' />";
$("#addLayer").append(textTag);
});
//$(document).on("์ด๋ฒคํธ", "selector", function(){});
$(document).on("click", ".alertbutton", function(){
console.log('click!!!');
});
});
</script>
body ๋จ
<body>
<input type="button" id="addBtn" value="ํด๋ฆญ" />
<input type="button" id="beforeButton" value="์ด์ ์ถ๊ฐ" />
<input type="button" id="afterButton" value="์ดํ ์ถ๊ฐ" />
<div id="addLayer">
</div>
<input type="button" id="alertButton" value="click" />
<select id="searchSel">
<option value="first"> first </option>
<option value="second"> second </option>
<option value="third"> third </option>
</select>
<input type="text" id="searchText" />
<input type="button" id="searchBTN" value="search"/>
</body>
๋๊ธ