jquery checkbox checked all / set value multiple input 값 일괄 적용

북마크 추가

체크박스 선택 시 전체 선택이나 input창에 value를 일괄 적으로 적용 할때는 name을 사용한다.

 

 ---- js

$("#check_all").unbind("click").bind("click" , function(e){

if($(this).prop("checked")) {

$('input:checkbox[name="check_box"]').each(function(index) {

$(this).prop("checked", true);                     //checked all

});

} else {

$('input:checkbox[name="check_box"]').each(function(index) {

$(this).prop("checked", false);                    //unchecked all

 });

}

});

 

-- html

 

<input type="checkbox"  id="check_all" value=""/><span>전체선택/해제</span>

 

<input type="checkbox" id="checkbox1" name="check_box">

<input type="checkbox" id="checkbox2" name="check_box">

<input type="checkbox" id="checkbox3" name="check_box">

.

.

.

.

 

demo :: http://trandent.com/jsTest/16271320154184

 

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

 

input창 값 일괄 적용 - name을 같은 이름으로

 

------ js

function btnOk(){

$("input[name=input_box]").val( $("#inputVal").val() );

}

 

------ html

 

<input type="text"  id="inputVal" value="" placeholder="값 입력"/>

 

<button type="button" onclick="btnOk()">일괄적용</button>

 

<input type="text" id="input_box1" name="input_box" placeholder="input 1">
<input type="text" id="input_box2" name="input_box" placeholder="input 2">
<input type="text" id="input_box3" name="input_box" placeholder="input 3">
<input type="text" id="input_box4" name="input_box" placeholder="input 4">
<input type="text" id="input_box5" name="input_box" placeholder="input 5">

 

demo :: http://trandent.com/jsTest/16392820155724

 

AD
통관알리미
2015-04-30 16:41
SHARE