jQuery获取this当前对象子元素对象的方法

<p>如下所示:</p><pre class="brush:js;toolbar:false">&lt;selectid=&quot;city&quot;&gt; &lt;optionvalue=&quot;beijing&quot;&gt;北京&lt;/option&gt; &lt;optionvalue=&quot;shanghai&quot;&gt;上海&lt;/option&gt; &lt;optionvalue=&quot;shenzhen&quot;&gt;深圳&lt;/option&gt; &lt;/select&gt; $(function(){ $(&quot;#city&quot;).change(function(){ ①//已获取select为当前this元素 }) })</pre><p>如果想要在①获取选中option的值可以有如下方法</p><p>$(&quot;#city option:selected&quot;).val(); //使用选择器</p><p>$(this).children(&#39;option:selected&#39;).val() //使用this</p><p>有时候我们会想当然的这样写 $(this &quot;a&quot;), $(&quot;this a&quot;)之类,这样是不对的</p><p>以上这篇jQuery获取this当前对象子元素对象的方法就是小编分享给大家的全部内容了。</p>
RangeTime:0.003289s
RangeMem:196.09 KB
返回顶部 留言