Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- utf-8
- replace
- lsusb
- javascript
- ajax
- 시놀로지
- RTL88x2BU
- println
- ASP
- SQL Injection
- include
- FileSystemObject
- disabled
- Injection
- Getrows
- XMLHTTP
- form
- euc-kr
- synology
- PHP GCM
- AC1300
- jQuery
- 크로스 컴파일
- 무선랜카드
- jquery 레이어
- 따라다니는 배너
- DS718+
- 커널
- readonly
- submit
Archives
- Today
- Total
아는 것이 좋은 것이다.
[jQuery] select option value 이외에 다른 값 사용하기(data 함수) 본문
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<select name="opt1" id="opt1">
<option value="main1" data-sub="sub1">main text 1</option>
<!--<option value="main1|sub1">main text 1</option>--><!-- 이와 같이 value에 구분자로 넣어서 사용할 수도 있지만 data 속성을 활용하여 사용 가능 -->
<option value="main2" data-sub="sub2">main text 2</option>
<option value="main3" data-sub="sub3">main text 3</option>
<option value="main4" data-sub="sub4">main text 4</option>
</select>
<p id="txt"></p>
<script>
$(function () {
$("#opt1").on("change", function () {
var value = $(this).val();
var subValue = $(this).find("option:selected").data("sub");
$("#txt").html(value + " : " + subValue);
});
});
</script>
</body>
</html>
select 태그 뿐만 아니라 다른 태그들도 data-**으로 사용 가능하다.
'jQuery' 카테고리의 다른 글
[jQuqery] request parameter 받기 (0) | 2016.04.13 |
---|---|
[jQuery] 함수 생성후 호출 (0) | 2015.06.26 |
[jQuery] .trigger() 이벤트 강제 실행 함수 (0) | 2015.02.11 |
[jQuery] ajax 통신후 스크립트 먹통일 경우 (0) | 2015.02.09 |
[jQuery] asp, php 사용하지 않고 include 하기 (0) | 2014.07.13 |
Comments