Rumah > Artikel > hujung hadapan web > html5推出queryselectall之后,jQuery的作用是否减小了?
jQuery就是javascript和query(查询),html5推出queryselectall之后,可以更快的使用选择器查询了,jQuery的必要性是不是就没那么强了?
<code class="language-js"><span class="kd">var</span> <span class="nx">sections</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s1">'.section'</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">sections</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">--</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">sections</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">parentNode</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">sections</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
<span class="p">}</span>
</code>
题主的说法是对的,必要性显然是减小了。DOM 的接口每方便一点,引入 jQuery 的优势就减小一点。优势减小不等于没用嘛。
参考这个:jQuery会过时吗? - 贺师俊的回答
单就选择器来说,jquery的作用减小了。