예_ 폼 아이디가 form1 이고 그안의 name="param" 의 요소의 값을 가져 오고 싶은 경우.

 

$('#form1 [name="param"]').val()

 

이런식으로 하면 된다.

 

잘만사용하면 매우 깔끔하고 간편한 코딩을 할 수 있을듯? 



출처: https://fany4017.tistory.com/41 [황그래의 블로그]

'밥벌이 > jQuery' 카테고리의 다른 글

jQuery select box Control 제어  (0) 2019.10.22

데이터를 실수로 삭제(delete) 및 갱신(update) 후 commit 했다면

당황하지 말고 timestamp를 사용하여 삭제 및 갱신 전의 데이터를 조회하여 복구 할 수 있다.

 

 

SELECT  *  
  FROM "테이블명" AS OF TIMESTAMP(SYSTIMESTAMP-INTERVAL '10' MINUTE)

;

   

단위는 SECONDMINUTEHOURDAY로 바꿔 쓸 수 있다.
실수로 지운 데이터 당황하지 말고 바로 복구 하세요^^



 자바에서 배열을 출력하는 방법

 

그냥 배열을 출력

 

아래 코드와 같이 그냥 배열을 System.out.println 으로 출력해봅시다

 

1

2

3

4

5

6

7

8

public class PrintArray {

 

    public static void main(String[] args) {

        String[] arr = {"ABC","DEF","GHI"};

        System.out.println(arr);

    }

 

}

Colored by Color Scripter

 

 

1

[Ljava.lang.String;@7852e922

 

 

출력이 되긴 하는데 무언가 우리가 원하는 형태가 아니군요 ㅎㅎ;

 

내용을 보고 싶은데 말이죠 ㅎㅎ;;;

 

 

 

java.util.Arrays

java.util.Arrays의 toString 메서드를 사용하여 배열을 출력해봅시다.

 

1

2

3

4

5

6

7

8

9

10

import java.util.Arrays;

 

public class PrintArray {

 

    public static void main(String[] args) {

        String[] arr = {"ABC","DEF","GHI"};

        System.out.println(Arrays.toString(arr));

    }

 

}

Colored by Color Scripter

 

 

1

[ABC, DEF, GHI]

 

 

우리가 원하는 형태로 출력이 되는군요!!! ㅎㅎ



출처: https://korbillgates.tistory.com/120 [생물정보학자의 블로그]


jQuery로 선택된 값 읽기

$("#selectBox option:selected").val();

$("#select_box > option:selected").val()

$("select[name=name]").val();

 

jQuery로 선택된 내용 읽기

$("#selectBox option:selected").text();

 

선택된 위치

var index = $("#test option").index($("#test option:selected"));

 

-------------------------------------------------------------------

 

// Add options to the end of a select

$("#selectBox").append("<option value='1'>Apples</option>");

$("#selectBox").append("<option value='2'>After Apples</option>");

 

// Add options to the start of a select

$("#selectBox").prepend("<option value='0'>Before Apples</option>");

 

// Replace all the options with new options

$("#selectBox")

.html("<option value='1'>oranges</option><option value='2'>Oranges</option>");

 

// Replace items at a certain index

$("#selectBox option:eq(1)")

.replaceWith("<option value='2'>apples</option>");

$("#selectBox option:eq(2)")

.replaceWith("<option value='3'>bananas</option>");

 

// 지정된 index 값으로 select 하기

$("#selectBox option:eq(2)").attr("selected""selected");

 

// text 값으로 select 하기

$("#selectBox").val("Some oranges").attr("selected""selected");

 

// value 값으로 select 하기

$("#selectBox").val("2");

$("#selectBox > option[@value=지정값]").attr("selected", "true");

 

// 지정된 인덱스 값의 item 삭제

$("#selectBox option:eq(0)").remove();

 

// 첫번째 item 삭제

$("#selectBox option:first").remove();

 

// 마지막 item 삭제

$("#selectBox option:last").remove();

 

// 선택된 옵션의 text 구하기

alert($("#selectBox option:selected").text());

 

// 선택된 옵션의 value 구하기

alert($("#selectBox option:selected").val());

 

// 선택된 옵션 index 구하기

alert($("#selectBox option").index($("#selectBox option:selected")));

 

// SelecBox 아이템 갯수 구하기

alert($("#selectBox option").size());

 

// 선택된 옵션 앞의 아이템 갯수

alert($("#selectBox option:selected").prevAll().size());

 

// 선택된 옵션 후의 아이템 갯수

alert($("#selectBox option:selected").nextAll().size());

 

// 0번째 item 다음에 삽입

$("#selectBox option:eq(0)").after("<option value='4'>Some pears</option>");

 

// 3번째 item 전에 삽입

$("#selectBox option:eq(3)").before("<option value='5'>Some apricots</option>");

 

// select box 값이 변경될때 선택된 현재값

$("#selectBox").change(function() {

           alert($(this).val());

           alert($(this).children("option:selected").text());

});




출처 : http://blog.daum.net/twinsnow/124

'밥벌이 > jQuery' 카테고리의 다른 글

[jquery] 특정 폼안의 요소 가져오기  (0) 2021.01.26

jsp내에서 jstl if문사용 (조건문)

jsp내에서 if else 자주 까먹는 부분입니다.
java와 조금 다른대요 아래의 예제로 알아봅시다.

============ test.jsp ============ 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:if test="true">실행결과 :</c:if>
<c:set var="iNum1" value="1024"/>
<c:set var="iNum2" >2048</c:set>
<c:set var="sum" value="${iNum1+iNum2 }"/>
<c:if test="${iNum1+iNum2 ==sum }">같다</c:if>
<c:choose>
<c:when test="${iNum1+iNum2 ==sum }">같다</c:when>
<c:otherwise>다르다</c:otherwise>
</c:choose>
============ test.jsp ============

실행결과  : 같다 같다


===========[  설명  ]================

jsp내에서 jstl 의 if 문은 <c:if> 를 사용합니다.  else는 제공하지 않습니다.
jsp내에서 jstl의 if else는 switch 문인 <c: choose > <c:when> 을 사용합니다.


IF
<c:if test="조건식">같다</c:if>

IF ELSE
<c:choose>
<c:when test="조건식1"실행문장 </c:when>
<c:when test="조건식2"실행문장 </c:when>
<c:otherwise>위조건이외의 실행</c:otherwise>

'밥벌이 > JSP' 카테고리의 다른 글

JSTL 합계 계산  (0) 2017.03.03
var date = new Date(); 
var year = date.getFullYear(); 
var month = new String(date.getMonth()+1); 
var day = new String(date.getDate()); 

// 한자리수일 경우 0을 채워준다. 
if(month.length == 1){ 
  month = "0" + month; 
if(day.length == 1){ 
  day = "0" + day; 

$("#regDate").val(year + "" + month + "" + day);


1. 문자열에서 정수형으로 변환 (String to int)


- int i = Integer.parseInt(String str);




2. 정수형을 문자열로 변환 (int to String)


- String str = Integer.toString(int i);


- String str = String.valueOf(int i);  




3. 형식에 맞춰서 변수들을 문자열로 변환 (c언어의 printf 동일)


- int i; float f;


  String str = String.format("%d %f",i,f);




4. 문자열에서 다른 숫자형태로 변환


- float f = Float.parseFloat(String str);  // String to float


- double d = Double.parseDouble(String str); // String to double


- byte b = Byte.parseByte(String str); // String to byte


- long l = Long.parseLong(String str); // String to long


- short s = Short.parseShort(String str); // String to short




5. 다른 숫자형태에서 문자열로 변환


- String str = String.valueOf(boolean b); // true 또는 false가 str에 저장됩니다.


- String str = String.valueOf(char c); // char to String


- String str = String.valueOf(char[] data); // char array to String


- String str = String.valueOf(double d); // double to String


- String str = String.valueOf(float f); // float to String


- String str = String.valueOf(long l); // long to String


- String str = String.valueOf(Object o); // Object to String , o == null이면 "null" 이 되고 o != null이면 o.toString() 함수의 반환값이 str이 된다.


- String str = String.valueOf(char[] data, int offset, int count); // offset 의 index부터 count 개의 문자로 부분문자열 생성

JSTL 합계 계산 

jsp에서 단순히 화면에서 하단에 합계를 구하는 경우

<c:forEach > 를 이용한 결과를 구하는 방법

JSTL

<table>

// 변수 선언

<c:set var = "sum" value = "0" />

// <c:forEach > 시작

<c:forEach var="test" items="${infoList}">

<tr>

<td> ${test.column_id} </td>

</tr>

<c:set var= "sum" value="${sum + test.column_id}"/>

</c:forEach>

<tr>

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

</tr>

</table>

'밥벌이 > JSP' 카테고리의 다른 글

JSTL IF문 ELSE  (2) 2018.04.20

+ Recent posts