我编写了一段代码,基本上 Select 所有input type=text
个元素,如下所示:
$('.sys input[type=text]').each(function () {}
我怎么改成 Select input[type=text]
或select
呢?
我编写了一段代码,基本上 Select 所有input type=text
个元素,如下所示:
$('.sys input[type=text]').each(function () {}
我怎么改成 Select input[type=text]
或select
呢?
Using a normal css selector:
$('.sys input[type=text], .sys select').each(function() {...})
如果你不喜欢重复:
$('.sys').find('input[type=text],select').each(function() {...})
Or more concisely, pass in the context
argument:
$('input[type=text],select', '.sys').each(function() {...})
注:内部jQuery
将上述转换为find()
等效值
Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').
I personally find the first alternative to be the most readable :), your take though