Jquery选择器输入[type = text]') [英] Jquery selector input[type=text]')
本文介绍了Jquery选择器输入[type = text]')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写的代码基本上选择了所有 input type = text
这样的元素:
I wrote a code that basically selects all input type=text
element like this:
$('.sys input[type=text]').each(function () {}
如何更改它以选择输入[type = text]
或选择
?
推荐答案
使用普通的css选择器:
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()
等价物
Note: Internally jQuery
will convert the above to find()
equivalent
在内部,选择器上下文用.find()方法实现,
所以$('span',this)相当于$(this).find('span')。
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
这篇关于Jquery选择器输入[type = text]')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文