吉吉于

jQuery 抄袭笔记(13) : Parent()

摘自w3school:

parent() 获得当前匹配元素集合中每个元素的父元素,使用选择器进行筛选是可选的。

parents() 获得当前匹配元素集合中每个元素的祖先元素,使用选择器进行筛选是可选的。

如果给定一个表示 DOM 元素集合的 jQuery 对象,.parent() 方法允许我们在 DOM 树中搜索这些元素的父元素,并用匹配元素构造一个新的 jQuery 对象。.parents()和 .parent() 方法类似,不同的是后者沿 DOM 树向上遍历单一层级。

01 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
02 <html xmlns=“http://www.w3.org/1999/xhtml”>
03 </span>
04 <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312″ />
05 </span>Hello Lazynight!<span style="color: #ff4400; font-weight: bold;"></title></span><br /> <span style="color: #696969;">06</span> <span style="color: #ff4400; font-weight: bold;"><script </span><span style="color: #ffff00;">type=</span><span style="color: #d13800;">“text/javascript”</span> <span style="color: #ffff00;">src=</span><span style="color: #d13800;">“jquery-1.1.3.pack.js”</span><span style="color: #ff4400; font-weight: bold;">></script></span><br /> <span style="color: #696969;">07</span> <span style="color: #ff4400; font-weight: bold;"><script </span><span style="color: #ffff00;">type=</span><span style="color: #d13800;">“text/javascript”</span><span style="color: #ff4400; font-weight: bold;">></span><br /> <span style="color: #696969;">08</span> <span style="color: #c0c0c0;">$</span>(<span style="color: #c0c0c0;">document</span><span style="color: #c0c0c0;">).</span><span style="color: #c0c0c0;">ready</span>(<span style="color: #ff4400; font-weight: bold;">function</span><span style="color: #c0c0c0;">(){</span><br /> <span style="color: #696969;">09</span> <span style="color: #c0c0c0;">$</span>(<span style="color: #d13800;">“a”</span><span style="color: #c0c0c0;">).</span><span style="color: #c0c0c0;">hover</span>(<span style="color: #ff4400; font-weight: bold;">function</span><span style="color: #c0c0c0;">(){</span><br /> <span style="color: #f810b0;">10</span>     <span style="color: #c0c0c0;">$</span>(<span style="color: #ff4400; font-weight: bold;">this</span><span style="color: #c0c0c0;">).</span><span style="color: #c0c0c0;">parent</span><span style="color: #c0c0c0;">().</span><span style="color: #c0c0c0;">addClass</span>(<span style="color: #d13800;">“highlight”</span><span style="color: #c0c0c0;">);}</span><br /> <span style="color: #696969;">11</span>     <span style="color: #c0c0c0;">,</span><span style="color: #ff4400; font-weight: bold;">function</span><span style="color: #c0c0c0;">(){</span><br /> <span style="color: #696969;">12</span>     <span style="color: #c0c0c0;">$</span>(<span style="color: #ff4400; font-weight: bold;">this</span><span style="color: #c0c0c0;">).</span><span style="color: #c0c0c0;">parent</span><span style="color: #c0c0c0;">().</span><span style="color: #c0c0c0;">removeClass</span>(<span style="color: #d13800;">“highlight”</span><span style="color: #c0c0c0;">);}</span><br /> <span style="color: #696969;">13</span>     );<br /> <span style="color: #696969;">14</span> <span style="color: #c0c0c0;">});</span><br /> <span style="color: #f810b0;">15</span> <span style="color: #ff4400; font-weight: bold;"></script></span><br /> <span style="color: #696969;">16</span> <span style="color: #ff4400; font-weight: bold;"><style></span><br /> <span style="color: #696969;">17</span> <span style="color: #c0c0c0;">.highlight</span><span style="color: #c0c0c0;">{</span><br /> <span style="color: #696969;">18</span> <span style="color: #ff4400; font-weight: bold;">background</span><span style="color: #c0c0c0;">:</span><span style="color: #c0c0c0;">#000</span>;<br /> <span style="color: #696969;">19</span> <span style="color: #ff4400; font-weight: bold;">color</span><span style="color: #c0c0c0;">:</span><span style="color: #c0c0c0;">#fff</span>;<br /> <span style="color: #f810b0;">20</span> <span style="color: #ff4400; font-weight: bold;">border</span><span style="color: #c0c0c0;">:</span><span style="color: #c0c0c0;">1px</span> <span style="color: #ff4400; font-weight: bold;">solid</span>;<br /> <span style="color: #696969;">21</span> <span style="color: #c0c0c0;">}</span><br /> <span style="color: #696969;">22</span> <span style="color: #ff4400; font-weight: bold;"></style></span><br /> <span style="color: #696969;">23</span> <span style="color: #ff4400; font-weight: bold;"></head></span><br /> <span style="color: #696969;">24</span> <span style="color: #ff4400; font-weight: bold;"><body></span><br /> <span style="color: #f810b0;">25</span> <span style="color: #ff4400; font-weight: bold;"><p></span>Keyshia Cole – Fallin Out<span style="color: #ff4400; font-weight: bold;"><p><pre></span><br /> <span style="color: #696969;">26</span> Been sitting thinking about you and I am<br /> <span style="color: #696969;">27</span> wondering why were not getting along<br /> <span style="color: #696969;">28</span> <span style="color: #ff4400; font-weight: bold;"><a</span> <span style="color: #ffff00;">href=</span><span style="color: #d13800;">” “</span><span style="color: #ff4400; font-weight: bold;">></span>So frustrated cause<span style="color: #ff4400; font-weight: bold;"></a></span><br /> <span style="color: #696969;">29</span> what we had was a<br /> <span style="color: #f810b0;">30</span> happy home<br /> <span style="color: #696969;">31</span> I don’t know what the<br /> <span style="color: #696969;">32</span> situation is<br /> <span style="color: #696969;">33</span> But I could tell in the way we kiss<br /> <span style="color: #696969;">34</span> we don’t talk no more<br /> <span style="color: #f810b0;">35</span> it feels better when<br /> <span style="color: #696969;">36</span> I'm alone<br /> <span style="color: #696969;">37</span><br /> <span style="color: #696969;">38</span> Sometimes I feel like there’s no getting through to you<br /> <span style="color: #696969;">39</span> Like you don’t appreciate all that I do<br /> <span style="color: #f810b0;">40</span> You gotta show me that you want me to stay<br /> <span style="color: #696969;">41</span> Don’t turn and walk away<br /> <span style="color: #696969;">42</span><br /> <span style="color: #696969;">43</span> Baby I'm slowly falling out of<br /> <span style="color: #696969;">44</span> love with you I don’t know what to do<br /> <span style="color: #f810b0;">45</span> How did we end up here this way<br /> <span style="color: #696969;">46</span> what are we gonna do<br /> <span style="color: #696969;">47</span> <span style="color: #ff4400; font-weight: bold;"></pre></span><br /> <span style="color: #696969;">48</span> <span style="color: #ff4400; font-weight: bold;"></p></p></span><br /> <span style="color: #696969;">49</span> <span style="color: #ff4400; font-weight: bold;"><hr /></span><br /> <span style="color: #f810b0;">50</span> <span style="color: #ff4400; font-weight: bold;"><p></span><br /> <span style="color: #696969;">51</span> <span style="color: #ff4400; font-weight: bold;"><pre></span><br /> <span style="color: #696969;">52</span> Keyshia Cole – Fallin Out<br /> <span style="color: #696969;">53</span> Been sitting thinking about you and I am<br /> <span style="color: #696969;">54</span> wondering why were not getting along<br /> <span style="color: #f810b0;">55</span> <span style="color: #ff4400; font-weight: bold;"><a</span> <span style="color: #ffff00;">href=</span><span style="color: #d13800;">” “</span><span style="color: #ff4400; font-weight: bold;">></span>So frustrated cause<span style="color: #ff4400; font-weight: bold;"></a></span><br /> <span style="color: #696969;">56</span> what we had was a<br /> <span style="color: #696969;">57</span> happy home<br /> <span style="color: #696969;">58</span> I don’t know what the<br /> <span style="color: #696969;">59</span> situation is<br /> <span style="color: #f810b0;">60</span> But I could tell in the way we kiss<br /> <span style="color: #696969;">61</span> we don’t talk no more<br /> <span style="color: #696969;">62</span> it feels better when<br /> <span style="color: #696969;">63</span> I'm alone<br /> <span style="color: #696969;">64</span><br /> <span style="color: #f810b0;">65</span> Sometimes I feel like there’s no getting through to you<br /> <span style="color: #696969;">66</span> Like you don’t appreciate all that I do<br /> <span style="color: #696969;">67</span> You gotta show me that you want me to stay<br /> <span style="color: #696969;">68</span> Don’t turn and walk away<br /> <span style="color: #696969;">69</span><br /> <span style="color: #f810b0;">70</span> Baby I'm slowly falling out of<br /> <span style="color: #696969;">71</span> love with you I don’t know what to do<br /> <span style="color: #696969;">72</span> How did we end up here this way<br /> <span style="color: #696969;">73</span> what are we gonna do<br /> <span style="color: #696969;">74</span> <span style="color: #ff4400; font-weight: bold;"></pre></span><br /> <span style="color: #f810b0;">75</span> <span style="color: #ff4400; font-weight: bold;"></p></span><br /> <span style="color: #696969;">76</span><br /> <span style="color: #696969;">77</span> <span style="color: #ff4400; font-weight: bold;"></body></span><br /> <span style="color: #696969;">78</span> <span style="color: #ff4400; font-weight: bold;"></html></span> </div> <span style="color: #ff6600;"><a href="http://down.qiannao.com/space/file/flowerowl/-4e0a-4f20-5206-4eab/Lazy13_parents.rar/.page" target="_blank"><span style="color: #ff6600;">下载源码</span></a></span> 转载请注明:[于哲的博客][1] » [jQuery 抄袭笔记(13) : Parent()][2] [1]: http://lazynight.me [2]: http://lazynight.me/515.html </pre></span></p></span></pre></p></span></p></span></body></span>