使用jQuery在类中获取不同类型的输入 [英] Get inputs of different types in a class using jQuery

查看:76
本文介绍了使用jQuery在类中获取不同类型的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在JavaScript中有一个jquery函数,到目前为止我有这个代码,效果很好:

Say I have a jquery function within JavaScript and I have this code so far, which works great:

jQuery('div [class =someClass]输入[type =text]')。each(function(){// some code} ...

在上面的代码中,我如何定位多种类型的输入,如textArea,下拉列表等。我是jQuery的新手,所以我不知道谷歌搜索没有带来任何相关的格式!请帮助。

In the above code, how can I target multiple types of inputs such as textArea, drop-down list etc. I am pretty new to jQuery so I am not aware of the format a google search did not bring up anything of much relevance! Please help.

推荐答案

如果您乐意选择所有这些类型的后代元素:

If you're happy to select all descendent elements that are of these types:


  • 输入

  • textarea

  • 选择

  • 按钮

  • input
  • textarea
  • select
  • button

你可以使用 :输入选择器

you can use the :input selector.

jQuery('div.someClass :input').each(function() {...

否则,您可以使用多个选项在大选择器中执行此操作选择器正如尼克拉斯所说。最后一个选项是通过使用两个选项来缩短它。这个可能稍慢,但会更具可读性:

Otherwise, you can do this in a big selector using the multiple selector as Niklas suggests. One last option is to shorten this by using two selections. This may be slightly slower, but will be significantly more readable:

jQuery('div.someClass').find('input[type="text"], select, textarea').each(function(){...

请注意,我已使用类选择器来制作您的选择器有点整洁。

Note that I have used the class selector to make your selector a bit neater.

这篇关于使用jQuery在类中获取不同类型的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆