abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery选择器</title> <script type="text/javascript" src="
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery选择器</title> <script type="text/javascript" src="static/jquery-3.3.1.min.js"></script> <style type="text/css"> #box,.box,.box2{width: 100px;height: 100px;border: 1px solid #ccc;margin: 10px 50px;} .txt{border: 1px solid #ccc;display: block; width: 100px;height: 30px;line-height: 20px;text-align: center;} </style> </head> <body> <!-- 基本选择器 --> <!-- <div class="box"></div> <div id="box"></div> <span class="txt">php</span> --> <!-- 层级选择器 --> <!-- <ul> <li>1</li> <li>2</li> <li>3 <ul> <li>0</li> <li>0</li> <li>0</li> </ul> </li> <li>4</li> <li>5</li> <li>6</li> </ul> <form> <label>姓名</label> <input type="" name=""> <button>按钮</button> <button>单击</button> <button>双击</button> </form> --> <!-- 顺序选择器 --> <!-- <p id="box1">1</p> <p>2</p> <p>3</p> <p>4</p> <p>5</p> <p>6</p> --> <!-- 内容选择器 --> <!-- <div class="box2">html</div> <div class="box2">javascript</div> <div class="box2">jquery</div> <div class="box2">css</div> <div class="box2"><span>php</span></div> <div class="box2"></div> <div class="box2"><b></b></div> --> <!-- 属性选择器 --> <!-- <label>1</label><input type="text" name="new" id="woman"><br> <label>2</label><input type="password" name="new1" id="man"><br> <label>3</label><input name="" id="new"><br> <label>4</label><input type="button" value="按钮" name=""><br> --> <!-- 表单选择器 --> <form> 输入框1<input type="" name=""><br> 输入框2<input type="" name=""><br> 输入框3<input type="" name="" disabled=""><br> 输入框4<input type="" name=""><br> <select> <option selected="">教皇</option> <option>射手座</option> <option>白羊座</option> <option>双子座</option> <option>双鱼座</option> </select><br> 爱好: <label><input type="checkbox" name="">看书</label> <label><input type="checkbox" name="">游泳</label> <label><input type="checkbox" name="" checked>游戏</label> </form> <script type="text/javascript"> // 基本选择器 // $(function(){ // // $('.class')根据给定的class匹配元素 // $('.box').css('background','yellow'); // // $('#id')根据给定的id匹配元素 // $('#box').css('background','green'); // // $('标签名')根据给定的标签名匹配元素 // $('span').css('color','red'); // // $('*')匹配所有元素 // $('*').css('border-radius','20px'); // // $('.class','#id','element')匹配页面多个选择器 // $('.box,#box,span').css('background','#ccc'); // }) // 层级选择器 // $(function(){ // // $('父级元素>子集元素')给定父级元素下匹配所有子集元素 // $('ul>li').css('list-style','none'); // // $('祖先元素 后代元素')给定祖先元素下匹配所有后代元素 // $('ul li').css('font-size','20px'); // // $('prev+next')匹配紧跟在prev后面的next元素(同级) // $('label+input').css('height','50px'); // // $('prev~siblings')匹配prev元素后边所有的siblings元素 // $('label~button').css('background','red'); // }) // 顺序选择器 // $(function(){ // // 1.顺序 // // $(':first')第一个元素 // $('p:first').css('color','#ccc'); // // $(':last')第一个元素 // $('p:last').css('color','red'); // // 2.比较 // // $(':gt(x)')大于值X的元素 // $('p:gt(2)').css('font-size','20px'); // // $(':lt(x)(')小于值X的元素 // $('p:lt(2)').css('font-size','30px'); // // $(':eq(x)')等于值X的元素 // $('p:eq(2)').css('color','blue'); // // 3.奇偶数 // // $(':odd')奇数顺序 // $('p:odd').css('background','pink'); // // $(':even')偶数顺序 // $('p:even').css('background','green'); // // 4.非 // // $(':ont(selector)')匹配不是selector的所有元素 // $('p:not(#box1)').css('background','red'); // }) // 内容选择器 // $(function(){ // // $(':contains(text)')匹配包含给定文本的元素 // $('div:contains(html)').css('background','red'); // // $(':has(selector)')匹配包含特定选择器的元素 // $('div:has(span)').css('color','blue'); // // $(':empty')匹配不含有内容的元素 // $('div:empty').css('background','red'); // // $(':parent')匹配含有子元素或文本的元素 // $('div:parent').css('background','yellow'); // }) // 属性选择器 // $(function(){ // // $('[属性名]')匹配包含给定属性的元素 // $('input[type]').css('background','blue'); // // $('[attribute=value]')匹配给定属性是某个特定值的元素 // $('input[type=button]').css('background','red'); // // $('[attribute!=value]')匹配所有不含有指定元素值的属性 // $('input[type!=text]').css('background','green'); // // $('[attribute^=value]')匹配给定属性是以某些值开始的元素 // $('input[type^=t]').css('background','red'); // // $('[attribute$=value]')匹配给定属性是以某些值开始的元素 // $('input[type$=n]').css('background','yellow'); // // $('[attribute*=value]')匹配给定属性包含某些值的元素 // $('input[type*=s]').css('background','black'); // // $('attrsel[1]attrsel[1]attrsel[1]')复合选择器,需要同时满足多个条件 // $('input[id][name*=n]').css('background','blue'); // }) // 表单选择器 $(function(){ // $(':enabled')所有激活的input元素 $('input:enabled').css('background','red'); // $(':disabled')所有禁用的input元素 $(':disabled').css('background','blue'); // $(':selected')所有被选取的元素 $(':selected').css('color','red'); // $(':checked')所有被选中的input元素 $(':checked').parent('label').css('color','blue'); }) </script> </body> </html>
Correcting teacher:查无此人Correction time:2019-05-13 09:26:08
Teacher's summary:完成的不错。jq比js简单很多,多练习。继续加油。