jquery

[jquery] 문제를 통한 jquery 이벤트 및 메서드 사용예제

sian han 2022. 5. 7. 19:35

 

 

 

 

function target02(){
	$("#target02 span").text("변경");
}

 $(selector).text(value); : 값넣기

 

 

 

 

 

function target06(){
	//$(".target06 input:checkbox").removeAttr("checked");
	$(".target06 input:checkbox").prop("checked", false);
}

.prop() 지정한 선택자를 가진 첫 번째 요소의 속성값을 가져오거나 속성값을 추가함

 

 

 

 

 

 

function target08(){
	$(".target08 select option").eq(1).attr("selected","selected");
}

attr( name, value ) : 택한 요소에 속성을 추가함

 

 

 

 

 

 

function target14(){
	$("#target14 table tr:eq(0)").appendTo("#target14 table");
}

appendTo() : 매개변수로 들어온 content 를 개채 "내부" 뒤쪽에 덧붙이는 메서드

 

 

 

 

 

 

function taget15(){	
	$("#target15 table tbody tr").each(function(idx, item){
		var a=parseInt($(item).find("td").eq(0).text());
		var b=parseInt($(item).children("td").eq(2).text());
		$(item).children("td").eq(4).text(a+b);		
	});
}

find(expr) : 현재 검색된 요소의 자식을 대상으로 추가적인 검색을 수행

 

 

 

 

 

 

function target17(){
var bool=false;
	setInterval(function(){
		var color=(bool?"red":"yellow");
		$("#target17").css("background", color);
		bool=!bool;
	},1000);
}

setinterval() : 설정된 시간마다 반복되는 함수

  - setinterval(실행함수, 밀리초) 

 

 

 

 

 

 

function target18(){
	$("#target18").children(":contains(bold)").css("font-weight","bold");
}

:contains() : 특정 문자열을 포함한 요소를 선택하는 선택자

 

 

 

 

 

function target19(){
	$("#target19").empty();
}

empty() : 선택한 요소의 내용을 지움

  - 내용만 지울 뿐 태그는 남아있다 !! = 태그포함 요소 전체를 지우고싶다면 .remove() 사용

 

 

 

 

 

 

 

function target16(){
	$("#target16 td").each(function(i){
	    var num=parseInt($(this).text());
	    if(num>10){
	         $(this).css("background","orange"); 
	    }
	});
}

 

 

 

 

 

 

 

function target20(){
	$("#target20 input:text").css("color","red").attr("readonly","readonly");
}