案例一:全选等
运用知识点:ondblclick=()| onclick | 寻找标签属性及判断和函数的应用
<Meta charset="UTF-8">
//全选的话先获取所有的input标签属性,然后全部为true
function checkAll(){
var tb = document.getElementById('tb');//获取tb,也就是身体
var checks = tb.getElementsByClassName('c1');
//[第一个,2,3,4,5]checked = true
for (var i=0;i获取tb,也就是身体
var checks = tb.getElementsByClassName('c1');
//[第一个,2,3,4,5]checked = true
for (var i=0;i
用户名 | 年龄 |
---|
function reverseAll(){
var tb = document.getElementById('tb');//<a href="https://www.jb51.cc/tag/huoqu/" target="_blank" class="keywords">获取</a>tb,也就是身体
var checks = tb.getElementsByClassName('c1');
//[第一个,2,3,4,5]checked = true
for (var i=0;i<checks.length; i++){
var current_check = checks[i];//得到每个input的值并赋一个变量名
if(current_check.checked <!--这个地方如果为true-->){
current_check.checked = false;
}else{
current_check.checked = true;
}
}
}
</script>
案例二:单选
要求只能选一个,并且用js可以改变其选项运用知识点:getElementsByTagName | checked | 互斥
>香甜鸡尾酒
</div>
</div>
</div>
<script>
function Show(ths){
//ths表示当前<a href="https://www.jb51.cc/tag/biaoqian/" target="_blank" class="keywords">标签</a>
var target = ths.getAttribute('target')//h3
//给自己<a href="https://www.jb51.cc/tag/tianjia/" target="_blank" class="keywords">添加</a>样式active
//兄弟们去掉
ths.className = 'active';
var brothers = ths.parentElement.children;
for(var i=0;i<brothers.length;i++){
if ( ths == brothers[i]){
}else{
brothers[i].removeAttribute('class')
}
}
//操作<a href="https://www.jb51.cc/tag/neirong/" target="_blank" class="keywords">内容</a>
var contents = document.getElementById('content').children;
console.log(contents)
for (var j=0;j<contents.length;j++){
var current_content = contents[j];
console.log(current_content)
var con = current_content.getAttribute('con')
if (con == target){
current_content.classList.remove('hide');
}else{
current_content.className="hide";
}
}
}
</script>