Home > Web Front-end > JS Tutorial > jQuery method to get the child element object of this current object

jQuery method to get the child element object of this current object

高洛峰
Release: 2016-12-03 15:25:03
Original
1457 people have browsed it

As shown below:

<select id="city">
   <option value="beijing">北京</option>
   <option value="shanghai">上海</option>
   <option value="shenzhen">深圳</option>
</select>
$(function(){
  $("#city").change(function(){
    ①// 已获取select为当前this元素
  })
})
Copy after login

If you want to get the value of the selected option in ①, you can use the following method

$("#city option:selected").val(); //使用选择器
$(this).children(&#39;option:selected&#39;).val() //使用this
Copy after login

Sometimes we take it for granted and write $(this "a"), $ ("this a") etc., this is wrong


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template