i'm trying to select some form elements when focusin and with this:$('textarea, input, select', '.highlightRow').live('focusin', function(e){ $(this).css("background-color","yellow"); });but there is something wrong with multiple selectors and contextwhen i use context and form don't have .highlightRow my textarea not change bgcolor (it's ok) but next elements in list (input, select) change bgcolor (it's wrong)example: http://jsfiddle.net/RgEAw/1/now only less elegant solution work ok:$('.highlightRow input, .highlightRow .highlightRow select, .highlightRow textarea')...is there any posibilities to use this multiple selector and context in this situation? 解决方案 According to the jQuery doc, the context must be "a DOM Element, Document, or jQuery". It cannot itself be a string selector.So, when you specify this:$('textarea, input, select', '.highlightRow')you are apparently trying to specify a context of '.highlightRow' which is not one of the documented methods of specifying a context. In this particular case, you can either get a single DOM element for '.highlightRow', turn it into a jQuery object or put it into the actual selector. But, context will ONLY work if the object you are passing actually exists. If it doesn't exist, then it's like you're passing a NULL context which means to search the whole document so it doesn't do what you want. So, you can only use the context parameter in the selector when it actually exists.I would suggest using this:$('.highlightRow textarea, .highlightRow input, .highlightRow select')Working demo here: http://jsfiddle.net/jfriend00/uzYuQ/. 这篇关于多个选择器不与上下文一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-09 23:04