728x90
๋ฐ์ํ
// select box ID๋ก ์ ๊ทผํ์ฌ ์ ํ๋ ๊ฐ ์ฝ๊ธฐ
$("#์
๋ ํธ๋ฐ์คID option:selected").val();
// select box Name๋ก ์ ๊ทผํ์ฌ ์ ํ๋ ๊ฐ ์ฝ๊ธฐ
$("select[name=์
๋ ํธ๋ฐ์คname]").val();
// ๊ฐ์ ๋ฐฉ์์ผ๋ก span๊ณผ ๊ฐ์ ๋ค๋ฅธ ํ๊ทธ๋ ์ ๊ทผ ๊ฐ๋ฅํ๋ค~
$("span[name=์
๋ ํธ๋ฐ์คname]").text();
// ์ ํ๋ ๊ฐ์ index๋ฅผ ๋ถ๋ฌ์ค๊ธฐ
var index = $("#์
๋ ํธ๋ฐ์คID option").index($("#์
๋ ํธ๋ฐ์คID option:selected"));
// ์
๋ ํธ ๋ฐ์ค์ option๊ฐ ์ถ๊ฐํ๊ธฐ
$("#์
๋ ํธ๋ฐ์คID").append("<option value='1'>1๋ฒ</option>");
// ์
๋ ํธ ๋ฐ์ค option์ ๋งจ์์ ์ถ๊ฐ ํ ๊ฒฝ์ฐ
$("#์
๋ ํธ๋ฐ์คID").prepend("<option value='0'>0๋ฒ</option>");
// ์
๋ ํธ ๋ฐ์ค์ html ์ ์ฒด๋ฅผ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ
$("#์
๋ ํธ๋ฐ์คID").html("<option value='1'>1์ฐจ</option><option value='2'>2์ฐจ</option>");
// ์
๋ ํธ ๋ฐ์ค์ index๋ณ๋ก replace๋ฅผ ํ ๊ฒฝ์ฐ
// ํด๋น ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ค๊ฒ ๋๋ฉด, option์ด ๋ค์๊ฐ ๋๋ฏ๋ก ๋ฐฐ์ด ๊ฐ์ฒด๊ฐ ๋์ด eq์ index๋ฅผ ๋ฃ์ด ๊ฐ๋ณ ๊ฐ์ฒด๋ฅผ ์ ํํ ์ ์๋ค.
$("#์
๋ ํธ๋ฐ์คID option:eq(1)").replaceWith("<option value='1'>1์ฐจ</option>");
// ์ง์ index ๊ฐ์ ์ฃผ์ด selected ์์ฑ ์ฃผ๊ธฐ
$("#์
๋ ํธID option:eq(1)").attr("selected", "selected");
// text ๊ฐ์ผ๋ก selected ์์ฑ ์ฃผ๊ธฐ
$("#์
๋ ํธID")val("1๋ฒ").attr("selected", "selected");
or
$("#id").text("1๋ฒ").attr("selected", "selected");
// value ๊ฐ์ผ๋ก selected ์์ฑ ์ฃผ๊ธฐ
$("#์
๋ ํธID").val("1");
or
$("#id").val("1").prop("selected", true);
// ํด๋น index item ์ญ์ ํ๊ธฐ
$("#์
๋ ํธID option:eq(0)").remove();
// ์ฒซ๋ฒ์งธ, ๋ง์ง๋ง item ์ญ์ ํ๊ธฐ
$("#์
๋ ํธID option:first").remove();
$("#์
๋ ํธID option:last").remove();
// ์ ํ๋ ์ต์
์ text, value ๊ตฌํ๊ธฐ
$("#์
๋ ํธID option:selected").text();
$("#์
๋ ํธID option:selected").val();
// ์ ํ๋ ์ต์
์ index ๊ตฌํ๊ธฐ
$("#์
๋ ํธID option").index($("#์
๋ ํธID option:selected"));
// ์
๋ ํธ๋ฐ์ค์ ์์ดํ
๊ฐฏ์ ๊ตฌํ๊ธฐ
$("#์
๋ ํธID option").size();
// ์ ํ๋ ์ต์
์ ๊น์ง์ item ๊ฐฏ์ ๊ตฌํ๊ธฐ
$("#์
๋ ํธID option:selected").prevAll().size();
// ์ ํ๋ ์ต์
ํ์ item ๊ฐฏ์ ๊ตฌํ๊ธฐ
$("#์
๋ ํธID option:selected").nextAll().size();
// ํด๋น index item ์ดํ์ option item ์ถ๊ฐ ํ๊ธฐ
$("#์
๋ ํธID option:eq(0)").after("<option value='3'>3๋ฒ</option>");
// ํด๋น index item ์ ์ option item ์ถ๊ฐํ๊ธฐ
$("#์
๋ ํธID option:eq(3)").before("<option value='2'>2๋ฒ</option>");
// ํด๋น ์
๋ ํธ ๋ฐ์ค์ change event binding ํ๊ธฐ
$("#selectID").change(function() {
alert($(this).val());
alert($(this).children("option:selected").text());
});
<select name='wr_2'>
<option value='1'>1 ์ </option>
<option value='2'>2 ์ </option>
<option value='3'>3 ์ </option>
<option value='5'>5 ์ </option>
</select>
$("select[name=wr_2]").val(<?php echo $write['wr_2']?>).attr("selected", "selected");
์ถ์ฒ : https://howcode.co.kr/bbs/board.php?bo_table=jquery&wr_id=3
๋ฐ์ํ
'js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
jquery ํจ์จ์ ์ผ๋ก ์์ฑํ๋ ๋ฐฉ๋ฒ (0) | 2019.12.12 |
---|---|
bxslider ์ฌ์ฉ๋ฒ ๋ฐ ์ต์ ๋ชจ์ (0) | 2019.02.11 |
๋ง์ฐ์ค ํธ๋ฒ ํ์ ๋ ์ด๋ฏธ์ง ๋ณ๊ฒฝํ๊ธฐ (hover img on off replace) (0) | 2019.01.25 |
click event ํ๋๋ง (0) | 2019.01.23 |
jq ์ฒดํฌ๋ฐ์ค ํด๋ฆญ ์ด๋ฒคํธ์ input (0) | 2019.01.18 |