<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery 01 simples</title>
<script src="js/jquery-1.12.1.js" type="text/javascript"></script>
<script type="text/javascript">
function test(){
//console.log($);
//console.log(jQuery);
/**
* 原生的DOM对象
*
* jQuery对象:对原生对象进行包装
*
*
* 转换:如果是jquery对象转换为dom对象 jquery.get(0) jquery[0]
*
* 如果是原始的dom对象转换为jquery对象 $(dom) jQuery(dom)
*
* @type {NodeList}
*/
$("h1").remove();
var h1s = document.getElementsByTagName("h1");
for(var i=0;i<h1s.length;i++){
var h1 = h1s[i];
h1.parentNode.removeChild(h1);
}
}
/**
* onload函数和自执行函数的区别
*
* onload:是将页面加载完成以后再执行相应的函数 此时 页面的各个内容已经初始化完成
*
* 自执行函数:只要解析到 就会执行 而不会管你页面是否初始化完成
*
*/
/*(function(){
console.log("init....");
var h1s = document.getElementsByTagName("h1");
for(var i=0;i<h1s.length;i++){
var h1 = h1s[i];
h1.parentNode.removeChild(h1);
}
})();*/
window.onload = function(){
console.log("init....");
var h1s = document.getElementsByTagName("h1");
console.log(h1s.length)
for(var j=h1s.length-1;j>=0;j--){
var h1 = h1s[j];
h1.parentNode.removeChild(h1);
}
}
window.onload = function(){
console.log("init1....");
}
/*window.onload = function(){
test();
}*/
</script>
</head>
<body>
<input type="button" value="test" onclick="test();">
<hr>
<div>
<span>this is a span in div 1</span><span>this is a span in div 2</span><span>this is a span in div 3</span><span>this is a span in div 4</span>
<h1>this is a h1</h1>
<h1>this is a h1</h1>
<h1>this is a h1</h1>
<h1>this is a h1</h1>
</div>
</body>
</html>