1.定时按钮
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>按钮定时</title></head><body><button disabled>同意</button><script src="../jquery.js"></script><script>setTimeout(function(){console.log($("button"))$("button").removeAttr("disabled")},5000)</script></body></html>
2.隐藏显示div
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>div</title><style>div{width: 100px;height: 100px;border: 2px solid black;}.box1{display: none;}button:focus{outline: 1px solid rgb(19, 166, 224);}</style></head><body><div class="box1">中国万岁</div><div class="box1">世界万岁</div><div class="box2">宇宙万岁</div><button>显示并且改变颜色</button><script src="../jquery.js"></script><script>$("button").click(function(){let div = $(".box1")div.css({"display":"block","background-color":"green"})})</script></body></html>
3.选择框选中
注:更简单办法 - 不遍历
$(“select option[value=’”+inhobby+”‘]”).attr(‘selected’,true)
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>选择器的使用</title></head><body><label for="">请输入爱好:</label><input type="text" name="hobby" id=hobby><br/><label for="">爱好下拉列表</label><select name="" id="select" ><option value="编程">编程</option><option value="篮球">篮球</option><option value="滑板">滑板</option><option value="听音乐">听音乐</option></select><br/><button>判断</button><script src="../jquery.js"></script><script>$("button").click(function(){let inhobby = $("#hobby").val();$("select option").each(function() {if($(this).val()==inhobby){$("select").val(inhobby);}});})</script></body></html>
4.复选框选中
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>复选框</title><style>.box2{background-color: indianred;}</style></head><body><!-- <form action=""> --><div class="box1">请输入城市:<input type="text" id="city"></div>城市复选框:<br/><div class="box2"><input type="checkbox" name="" id="" value="北京">北京<input type="checkbox" name="" id="" value="南京">南京<input type="checkbox" name="" id="" value="上海">上海</div><button>判断</button><!-- </form> --><script src="../jquery.js"></script><script>$("button").click(function(){let incity = $("#city").val();$(".box2 input").each(function() {if($(this).val()==incity){$(this).attr('checked','true')}});})</script></body></html>
5.隔行变色
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>隔行变色</title><style>table{width: 200px;height: 100px;text-align: center;}</style></head><body><table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody><tr><td>Cherry</td><td>22</td></tr><tr><td>Lynn</td><td>23</td></tr><tr><td>Tracer</td><td>23</td></tr></tbody></table><script src="../jquery.js"></script><script>$("thead tr").css("background-color","lightgray")$("tbody tr:even").css("background-color","red")$("tbody tr:odd").css("background-color","green")</script></body></html>
