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

高洛峰
高洛峰Original
2016-12-03 15:25:031463browse

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元素
  })
})

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

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


Statement:
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