此方法选取匹配所有不可见元素,或者type为hidden的元素(包括document文档中头元素)如下实例:
实例:
<!DOCTYPE html>
<html>
<head>
<meta charset=' utf-8'>
<meta name='author' content='http://www.52jb.net/' />
<script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
<title>Inset you title</title>
<style type='text/css'>
*{margin:0;padding:0;}
div,form{150px;height:20px;margin:20px;}
#hidden,#user{display:none;}
#opacity{filter:alpha(opacity=0);opacity:0;}
</style>
<script type='text/javascript'>
$(function(){
/*
head,meta,meta,script,title,style,script,div[id='hidden'],input[type='hidden'],input[type='text']
*/
// alert($(':hidden').size()); //10
for( var i = 0 ; i < $(':hidden').size() ; i++ ){
// alert($(':hidden')[i]);
document.body.innerHTML += $(':hidden')[i].tagName.toLowerCase() +'<br/>';
}
});
</script>
</head>
<body>
<div id='hidden'>hidden element</div>
<div id='opacity'>opacity element</div>
<form id='form'>
<input type='text' id='user' />
<input type='hidden' class='hidden' value='hidden-form-input'/>
</form>
</body>
</html>