8.juery
代码1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < title >Title</ title > < style > #mysp{ display: none; } </ style > </ head > < body > < h1 class="myc">111</ h1 > < h1 class="myc">222</ h1 > < img src="mei.jpeg"/> < span id="mysp"> < button >图片回来</ button > </ span > < form > < input type="text" name="" id="id1" value="hello"/> < input type="text" name="" id="id2" value="hello2"/> </ form > < script src="jquery-3.6.0.js"></ script > < script > //jquery遍历数组 var arr1=['linzi1','linzi2','linzi3','linzi4']; $.each(arr1,function (key,value) { console.log(key,value); }) //jquery选择器 console.log($('title').html()); $('.myc').each(function (key,value) { $(value).css('color','red'); }); var var3=$('.myc').eq(1).html(); console.log(var3); //jquery事件绑定 $('.myc').eq(0).click(function () { console.log('jq事件'+$(this).html()); }) //juery鼠标事件 $('.myc').eq(1).mouseover(function () { console.log("juery鼠标事件"); }) //juery属性 $('#id1').val("linzi").attr("type",'password'); $('#id2').attr("maxlength",'2'); $('title').html("juery属性"); //juery隐藏显示 $('img').click(function () { $(this).hide(); $('#mysp').show(); }) $('#mysp').click(function () { $('img').show(); $(this).hide(); }) </ script > </ body > </ html > |
代码2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < title >Title</ title > < style > .active{ color: aqua; } </ style > </ head > < body > < button >小米</ button > < button >华为</ button > < button >苹果</ button > < div > < p class="brand0">小米1</ p > < p class="brand0">小米2</ p > < p class="brand1">华为1</ p > < p class="brand2">苹果1</ p > </ div > < script src="jquery-3.6.0.js"></ script > < script > $('button').each(function (index,item) { $(item).click(function () { $('p').hide(); $('.brand'+index).show(); $(this).addClass('active'); } ) }) </ script > </ body > </ html > |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步