JavaScript 및 Jquery 코드

6243 단어 JavaScriptjquerycss
document.onreadystatechange = function(){
	if(document.readState == "complete"){
		alert("      ," + document.radyState);
	}
	//do something
}


$(document).ready(function(){
	alert("Jquery loaded")	;
	//do something
});

//------------------------------------------

var textbox1 = document.getElementById("textbox1");
if(textbox1 != null && textbox1 != undefined){
	alert(textbox1.value);
}

$("#TextBox1").val();


//------------------------------------------------------

var tb_list = document.getElementsByTagName("input");
for(var i=0; i< tb_list.length; i++){
	alert(tb_list[i].name);
}

$("input").each(function(){
	alert($(this).attr("name"));
})

//----------------------------------------------

var tb_list = document.getElementsByTagName("input");
for (var i=0;i<tb_list.length; i++){
	if(tb_list[i].name.indexOf("TextBox") != -1){//indexOf       
		alert(tb_list[i].name);
	}
}

$("input[name*=\"TextBox\"]").each(function(){
	alert($(this).attr("name"));
})


//---------------------------------
var tb_list = document.getElementsByTagName("input");
for (var i=0;i<tb_list.length; i++){
	if(tb_list[i].name.indexOf("TextBox") != -1){
		tb_list[i].onclick = function(){
			alert(this.name);
		}
	}
}

$("input[name*=\"TextBox\"]").click(function(){//  name*=\"TextBox\"     
	alert($(this).attr("Name")); //attr("Name      ")
})

//-----------------------------------------------

//     checkbox     
var cb_list = document.getElementsByName("input");
var checked = "5";
for(var i=0; i<cb_list.length; i++){
	if(cb_list[i].type == "checkbox"){
		cb_list[i].checked = true;
	}
}



$("input[type=\"checkbox\"]").attr("checked",true);

//      
$("input[type=\"checkbox\"]").each(function(){
	$(this).attr("checked",true);
})

//     checkbox              true     false




//--------------------------------------------------------------------------------



//              
var tb_list = document.getElementsByTagName("input");
for(var i=0;i<tb_list.length;i++){
	if(tb_list[i].name.indexOf("TextBox") != -1){
		tb_list[i].style.width = "100";
		tb_list[i].style.height = "30";
		tb_list[i].style.border = "solid 1px red";
	}
}


$("input[name*=\"TextBox\"]").each(function(){
	$(this).css("height","30px").css("width","100px").css("border","solid 1px red");
	//  
	$(this).css({height: "30px", width: "100px", border: "solid 1px red"});
	//  
	$(this).height(30);
	$(this).width(100);
	$(this).css("border","solid 1px red");
})

//--------------------------------------------------------------------------------
//           
var parent = document.getElementById("div1").getElementsByTagName("input");
for(var i=0;i<parent.length;i++){
	parent[i].value = i;//0 1 2 3 4 5 6
}

$("#div1 > input").each(function(){
	$(this).val(i);
})

//--------------------------------------------------------------------------------
//  onmouseover onmouseout
var div_list = document.getElementById("divframe").getElementsByTagName("div");
for(var i=0;i<div_list.length;i++){
	div_list[i].onmouseover = function(){
		this.className = "f8";
	};
	div_list[i].onmouseout = function(){
		this.className = "";
	};
};


$("#divframe > div").mouseover(function(){
	$(this).addClass("f8");
}).mouseout(function(){
	$(this).removeClass("f8");
})







//--------------------------------------------------------------------------------
//          
var tb_list = document.getElementsByTabName("input");
for(var i=0;i<tb_list.length;i++){
	if(tb_list[i].type == "text"){
		tb_list[i].disabled = true;//  
		tb_list[i].disabled = false;//  
	}
}

$("input[type=\"text\"]").attr("disabled",true);
$("input[type=\"text\"]").attr("disabled",false);

//---------------------------------------------------
    
var tb_list = document.getElementsByTagName("input");
for(var i=0;i<tb_list.length;i++){
	if(tb_list[i].type == "text"){
		tb_list[i].onkeyup=function(){
			event.cancelBubble = true;
			event.returnValue = false;
			alert(event.keyCode);
		}
	}
}

$("input[type=\"text\"]").keyup(function(event){
	event.cancelBubble = true;
	event.returnValue = false;
	alert(event.keyCode);
});

//--------------------------------------------------------------------------------

Attribute.indexOf(value);

//         
Attribute                     
Attribute=value           value   
Attribute!=value          value    
Attribute^=value          value  
Attribute$=value          value  
Attribute*=value           value

for example:
$("input[id][name$=\"4\"][type=\"text\"]").val("i");
    :
1 input  
2   id  
3   name  ,  name  4  
4   type  ,  type   text

  :
            :i

좋은 웹페이지 즐겨찾기