jQuery获取this当前对象子元素对象

Love The Way You Lie 2022-08-17 15:28 291阅读 0赞
  1. <select id="city">
  2. <option value="beijing">北京</option>
  3. <option value="shanghai">上海</option>
  4. <option value="shenzhen">深圳</option>
  5. </select>
  6. $(function(){
  7. $("#city").change(function(){
  8. ①// 已获取select为当前this元素
  9. })
  10. })

如果想要在①获取选中option的值可以有如下方法

  1. $("#city option:selected").val(); //使用选择器
  2. $(this).children('option:selected').val() //使用this

有时候我们会想当然的这样写 $(this “a”), $(“this a”)之类,这样是不对的

作者:itmyhome

发表评论

表情:
评论列表 (有 0 条评论,291人围观)

还没有评论,来说两句吧...

相关阅读