jQuery¼¼Êõ

jQueryµÄÄÚÈݹýÂËÑ¡ÔñÆ÷ѧϰ½Ì³Ì

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-04-27 17:00 ÎÒÒªÆÀÂÛ( )

ITѧϰÍøÊǹúÄÚÒÔÆÕ¼°µçÄÔ¼¼ÊõµÄѧϰ×ÊÁÏÍøÕ¾,±¾Õ¾Àú¾­³¤ÆÚ·¢Õ¹ÒÑÉîµÃ¹ã´óµçÄÔ°®ºÃÕߵĺÃÆÀºÍϲ°®,ΪÄúÌṩ´Ó»ù´¡µ½¸ß¶ËµÄÐÅÏ¢¼¼Êõѧϰƽ̨£¬ÎÒÃÇҲŬÁ¦½«ITѧϰ

ÄÚÈݹýÂËÆ÷µÄ¹ýÂ˹æÔòÖ÷ÒªÊÇ°üº¬µÄ×ÓÔªËØ»òÎı¾ÄÚÈÝÉÏ¡£

2016418155237786.png (647¡Á339)


$('div:contains("xxx")').css('background', '#ccc'); //Ñ¡ÔñÔªËØÎı¾½Úµãº¬ÓÐxxx Îı¾µÄÔªËØ $('div:empty').css('background', '#ccc'); //Ñ¡Ôñ¿ÕÔªËØ $('ul:has(.red)').css('background', '#ccc'); //Ñ¡Ôñ×ÓÔªËغ¬ÓÐclass ÊÇred µÄÔªËØ $(':parent').css('background', '#ccc'); //Ñ¡Ôñ·Ç¿ÕÔªËØ

jQuery ÌṩÁËÒ»¸öhas()·½·¨À´Ìá¸ß:has ¹ýÂËÆ÷µÄÐÔÄÜ£º

$('ul').has('.red').css('background', '#ccc'); //Ñ¡Ôñ×ÓÔªËغ¬ÓÐclass ÊÇred µÄÔªËØ

jQuery ÌṩÁËÒ»¸öÃû³ÆºÍ:parent ÏàËƵķ½·¨£¬µ«Õâ¸ö·½·¨²¢²»ÊÇÑ¡È¡º¬ÓÐ×ÓÔªËØ»òÎı¾µÄÔªËØ£¬¶øÊÇ»ñÈ¡µ±Ç°ÔªËصĸ¸ÔªËØ£¬·µ»ØµÄÊÇÔªËؼ¯ºÏ¡£

$('li').parent().css('background', '#ccc'); //Ñ¡Ôñµ±Ç°ÔªËصĸ¸ÔªËØ $('li').parents().css('background', '#ccc'); //Ñ¡Ôñµ±Ç°ÔªËصĸ¸ÔªËؼ°×æÏÈÔªËØ $('li').parentsUntil('div').css('background', '#ccc'); //Ñ¡Ôñµ±Ç°ÔªËØÓöµ½div ¸¸ÔªËØÍ£Ö¹

jQueryÄÚÈݹýÂËÑ¡ÔñÆ÷µÄ¹ýÂ˹æÔòÖ÷ÒªÔËÓÃÔÚDOMÔªËØËù°üº¬µÄ×ÓÔªËØ»òÆäÎı¾ÄÚÈÝÉÏ£¬Ö÷Òª°üÀ¨ÒÔÏÂËÄÖÖ¹ýÂË·½·¨£º

ΪÁ˸üºÃµÄѧϰ£¬ÏÈд¼¸¸öDOMÔªËصÄHTML½á¹¹£º

<div>John Resign</div> <div>George Martin</div> <div>Malcom John Sinclair</div> <div>J.Ohn</div> <div></div> <p></p> <div><p>Has p</p></div>

Ò»¡¢ÄÚÈݹýÂËÑ¡ÔñÆ÷¡ª¡ª:contains(text)
Ñ¡ÔñÆ÷£º

E:contains(text)  //EÊÇÖ¸DOMÔªËØ£¬:contains(text)°üº¬µÄÎı¾£¬textÊÇÖ¸¶¨²éÕÒµÄ×Ö·û´®
ÃèÊö£º

Ñ¡È¡º¬ÓÐÎı¾ÄÚÈÝΪ¡°text¡±µÄÔªËØ

·µ»ØÖµ£º

¼¯ºÏÔªËØ

ʵÀý£º

<script type="text/javascript"> $(document).ready(function(){ $('div:contains(John)').css('background','#f36'); }); </script>

¹¦ÄÜ£º

¸Ä±äº¬ÓÐÎı¾Îª¡°John¡±µÄdivÔªËصı³¾°É«

Ч¹û£º

2016418154435377.png (313¡Á244)

»Øµ½Ç°ÃæµÄHTML½á¹¹ÖÐÎÒÃÇ¿ÉÒÔ¿´³öÆäÖÐÓÐÁ½¸ödivÔªËØÖаüº¬ÁË"John"Îı¾£¬ÒòΪÎÒÃÇÕâÀïÖ÷ÒªÊǸıäÁË°üº¬Îı¾¡°John¡±µÄdivµÄ±³¾°É«£¬Òò´Ë´ó¼ÒÔÚЧ¹ûÖпÉÒÔ¿´³öÎÒÃÇÆäÖеÚÒ»¸öºÍµÚÈý¸ödivµÄ±³¾°É«±ä³ÉÁË"#f36",ΪÁ˸üÄÜÌå»á´ÓÖеı仯£¬´ó¼Ò¿ÉÒÔͨ¹ýFirefoxÖеÄFirebug¹¤¾ß¿´³öHTMLµÄ±ä»¯£º

2016418154458800.png (596¡Á109)

¶þ¡¢ÄÚÈݹýÂËÑ¡ÔñÆ÷¡ª¡ª:empty

Ñ¡ÔñÆ÷£º

E:empty //ÆäÖÐEΪDOMÔªËØ£¬:emptyÊÇÖ¸DOMÔªËØÖв»°üº¬ÈκÎ×ÓÔªËØ»òÎı¾ 
ÃèÊö£º

Ñ¡È¡²»º¬ÈκÎ×ÓÔªËØ»òÎı¾µÄ¿ÕÔªËØ

·µ»ØÖµ£º

¼¯ºÏÔªËØ

ʵÀý£º

<script type="text/javascript"> $(document).ready(function(){ $('div:empty').css('background','#f36'); }); </script>

¹¦ÄÜ£º

¸Ä±ä²»º¬×ÓÔªËØ£¨°üÀ¨²»º¬Îı¾ÔªËØ£©µÄdivµÄ±³¾°É«£¬»»¾ä»°Ëµ£¬¾ÍÊǸı䲻°üº¬Èκζ«Î÷µÄdivµÄ±³¾°É«

Ч¹û£º

2016418154531426.png (312¡Á235)

ËäÈ»ÎÒÃÇÇ°ÃæµÄhtmlÖÐËùÓÐÔªËØÖв»°üº¬×ÓÔªËØ£¬µ«ÓÐһЩ°üº¬ÁËÎı¾ÔªËØ£¬Ö»ÓÐÒ»¸ödivºÍÒ»¸öpÔªËؾßûÓÐ×ÓÔªËØҲûÓÐÎı¾ÄÚÈÝ¡£¼ÓÉÏÎÒÃÇÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÖ»¶Ô²»°üº¬×ÓÔªËغÍÎı¾ÄÚÈݵÄdiv½øÐÐÁ˸ı䱳¾°É«µÄÉèÖã¬ËùÒÔÎÒÃǵÄЧ¹ûÖÐÖ»ÓÐdiv¼ÓÉÏÁË¡°#f36¡±µÄ±³¾°É«£¬Í¬ÑùÎÒÃÇÀ´¿´¿´HTMLµÄ±ä»¯°É£º

2016418154551068.png (510¡Á106)

Èý¡¢ÄÚÈݹýÂËÑ¡ÔñÆ÷¡ª¡ª:has(selector)

Ñ¡ÔñÆ÷£º

E:has(selector)  //ÆäÖÐEΪÓÐЧ¹ûDOMÔªËرêÇ©£¬:has(selector)º¬ÓÐÒ»¸öÑ¡ÔñÆ÷£¬selectorÓÃÓÚɸѡµÄÑ¡ÔñÆ÷

ÃèÊö£º

Ñ¡È¡º¬ÓÐÑ¡ÔñÆ÷ËùÆ¥ÅäµÄÔªËصÄÔªËØ

·µ»ØÖµ£º

¼¯ºÏÔªËØ

ʵÀý£º

<script type="text/javascript"> $(document).ready(function(){ $('div:has(p)').css('background','#f36'); }); </script>


¹¦ÄÜ£º
¸Ä±äº¬ÓÐ×ÓÔªËØPµÄdivÔªËصı³¾°É«
Ч¹û£º

2016418154627627.png (310¡Á246)

ÔÚÎÒÃÇÕâ¸öʵÀýÖУ¬Ö»ÓÐÒ»¸ödivÖаüº¬ÁË×ÓÔªËØP£¬ËùÒÔ°üº¬ÁË·ûºÏÕâ¸öÒªÇóµÄdivÔªËØÆä±³¾°É«±»ÉèÖÃΪ¡°#f36¡±£¬¸Ä±äºóµÄHTML:

2016418154652750.png (424¡Á138)

ËÄ¡¢ÄÚÈݹýÂËÑ¡ÔñÆ÷¡ª¡ª:parent

Ñ¡ÔñÆ÷£º

E:parent  //EΪÓÐЧµÄDOMÔªËرêÇ©£¬:parentº¬ÓÐ×ÓÔªËØ»òÎı¾ÄÚÈÝ¡£

ÃèÊö£º

Ñ¡È¡º¬ÓÐ×ÓÔªËØ»òÕßÎı¾µÄÔªËرêÇ©

·µ»ØÖµ£º

¼¯ºÏÔªËØ

ʵÀý£º

<script type="text/javascript"> $(document).ready(function(){ $('div:parent').css('background','#f36'); }); </script> 

¹¦ÄÜ£º
¸Ä±äº¬ÓÐ×ÓÔªËØ»òÎı¾ÄÚÈݵÄdivµÄ±³¾°É«¡£»»¾ä»°ËµÖ»ÔÚdiv°üº¬ÁËÈκÎÒ»¸ö×ÓÔªËØ»òÕßÈκÎÄÚÈÝ£¬Æä±³¾°É«¶¼½«»á¸Ä±ä¡£
Ч¹û£º

2016418154804725.png (313¡Á255)

±¾Àý×Ó£¬Ö»ÓÐÒ»¸ödivºÍÒ»¸öpÔªËØÖв»°üº¬ÈκÎ×ÓÔªËغÍÎı¾ÄÚÈÝ£¬ÒòΪÎÒÃÇÕâÀïÊǶÔdiv½øÐÐÉèÖã¬ËùÒÔЧ¹ûÖÐÏÔʾ£¬³ýÁËÕâÁ½¸ö²»º¬ÓÐ×ÓÔªËغÍÈκÎÄÚÈݵÄdivµÄ±³¾°É«¶¼±ä³ÉÁË¡°#f36¡±£¬±ä»¯ºóµÄHTML£º

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • jquery²å¼þJplayerʹÓ÷½·¨¼òÎö

    jquery²å¼þJplayerʹÓ÷½·¨¼òÎö

    2016-04-27 15:00

  • jQuery³£ÓõÄһЩ¼¼ÇÉ»ã×Ü

    jQuery³£ÓõÄһЩ¼¼ÇÉ»ã×Ü

    2016-04-04 11:03

  • jQuery+PHPÐǼ¶ÆÀ·ÖʵÏÖ·½·¨

    jQuery+PHPÐǼ¶ÆÀ·ÖʵÏÖ·½·¨

    2015-11-24 16:06

  • jqueryʵÏÖ¼òµ¥ÊµÓõĵ¯³ö²ãЧ¹û´úÂë

    jqueryʵÏÖ¼òµ¥ÊµÓõĵ¯³ö²ãЧ¹û´úÂë

    2015-11-20 16:39

ÍøÓѵãÆÀ
®