반응형
Select 박스 내가 원하는 값 선택하기 1 (스크립트 사용하기)

사용방법 :
HTML
<select id="test">
<option value="값1">선택1</option>
<option value="값2">선택2</option>
<option value="값3">선택3</option>
<option value="값4">선택4</option>
<option value="값5">선택5</option>
</select>

script 
<script>
//id값이 'test' 인 select 박스에서
//option value '값2' 이 선택됩니다
selectedOption('test', '값2', 'value');
//option text "선택4" 값이 선택됩니다.
selectedOption('test', '선택4', 'text');
</script>


<script>
function selectedOption(id, value, type) {
var obj = document.getElementById(id);
   
for(i=0; i<obj.length; i++) {
switch(type) {
case 'value' :
if(obj[i].value == value) {
obj[i].selected = true;
}
break;
           
case 'text' :
if(obj[i].text == value) {
obj[i].selected = true;
}
break;

default :
break;
}
}   
}
</script>


Select 박스 내가 원하는 값 선택하기2 (jstl 사용 하기)
<select name='popUpTerm' id='popUpTerm' data-validate='required' title='팝업노출기간'>
<option value='' >--선택--</option>
<option value='1' <c:if test="${noticeView.POPUP_TERM_DAY eq '1'}">selected="selected"</c:if>> 1일 후까지 노출</option>
<option value='2' <c:if test="${noticeView.POPUP_TERM_DAY eq '2'}">selected="selected"</c:if>> 2일 후까지 노출</option>
<option value='3' <c:if test="${noticeView.POPUP_TERM_DAY eq '3'}">selected="selected"</c:if>> 3일 후까지 노출</option>
<option value='4' <c:if test="${noticeView.POPUP_TERM_DAY eq '4'}">selected="selected"</c:if>> 4일 후까지 노출</option>
</select>


checkbox check되어있는지 확인
$("#id").click(function(){
if ($(this).is(':checked')==true){ //off to on
alert($(this).is(':checked') );
}else{//on to off
alert($(this).is(':checked') );
}
});



반응형

'개발의 흔적 > Front' 카테고리의 다른 글

CSS정리  (0) 2016.02.22
HTML정리  (0) 2016.02.22
JQuery 선택자의 종류(HTML 태그명, ID명에 접근하는 방법)  (0) 2016.02.01
input 박스 name과 id의 차이  (0) 2016.02.01
jstl 사용법  (0) 2016.01.22
반응형

JSTL(JavaServer Pages Standard Tag Library, 약칭 JSTL)은 

Java EE 기반의 웹 애플리케이션 개발 플랫폼을 위한 컴포넌트 모음

 

JSP 페이지에 태그라이브러리를 추가한 후 사용해야함

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

문법
1. c:forEach
- 속성
Items : 반복 데이터가 있는 아이템 Collection
begin : 시작번호 기본값 0
end   : 종료번호
step  : 증가분
var   : 현재 아이템의 변수 이름
varStatus : 반복 상태 값을 지닌 변수 
request.setAttribute("AList", list);

- 예제
<c:forEach var= "list" items ="${result}" varStatus="status" >
<tr>
<td> ${list.SEQ}</td>
<td><a href ="/notice/noticeView.do?seq=${list.SEQ} ">${list.TITLE}</a></td>
<td> ${list.W_USR}</td><td> ${list.W_DATE}</td></tr>
</c:forEach>

2. c:if
<c:set var= "변수명" value ="${noticeView.POPUP_TERM_DAY}" />
     <c:if test= "${popup_term_day eq '1'}">
          <option value= '1' > 1일 후까지 노출</option>
     </c:if>

- IF 문장 기본
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='5'}">
You guessed my number!
</c:if>

<c:if test="${param.guess!='5'}">
You did not guess my number!
</c:if>
</c:if>


- if ~ else 문
<c:if test="${pageContext.request.method=='POST'}">
Ok, we'll send 
<c:out value="${param.enter}" />

<c:choose>
<c:when test="${param.enter=='1'}">
pizza.
</c:when>

<c:otherwise>
pizzas.
</c:otherwise>
</c:choose>
</c:if>


- 논리 연산자 And와 Or을 이용한 if
<c:set var="guess" value="12"/>
<c:out value="${guess}"/>

<c:if test="${(guess >= 10)  && (guess <= 20)}">
<b>You're in range!</b><br/>
</c:if>

<c:if test="${(guess < 10)  || (guess > 20)}">
<b>Try again!</b><br/>
</c:if>


- true 값과 if문의 처리
<c:if test="true">Hello world!</c:if>


- 본문이 없이 if구문 처리하는 예제
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='5'}" var="result" />
I tested to see if you picked my number, the result was 
<c:out value="${result}" />
</c:if>


- 테스트 결과를 변수에 넣기, 이렇게 해서 결과를 재 사용할 수 있다.
<c:if test="${1==1}" var="theTruth" scope="session"/>

The result of testing for (1==1is: ${theTruth}
<h3>Conditionally execute the body</h3>

<c:if test="${2>0}">
It's true that (2>0)!
</c:if>


- 널과 Boolean 
<c:set var="StrVar" value="true"/>
<c:if test="${StrVar}">
equal!
</c:if><br/>

null == null
<c:out value="${null == null}"/>



2. c:choose
<c:choose>
<c:when test= "${dept_list.DEPT_SEQ == member.DEPT_SEQ}" >
<option value= '1' > 1일 후까지 노출</option>
</c:when>
<c:otherwise>
<option value= '2' > 2일 후까지 노출</option>
</c:otherwise>

</c:choose>


반응형

+ Recent posts