Normally when I use a class as a selector I try to use an "id" selector with it so it does not search through the entire page but only an area where the class would be.
然而,我有一个局部视图,其中包含代码.这个局部视图(公共代码)被包装在一个表单标记周围.
我有:
<form id="Create">
// load common code in from partial view
</form>
<form id="Edit">
// load common code in from partial view
</form>
现在,在这段通用代码中,我需要将一个插件附加到多个字段,这样我就可以
$('#Create .myClass').plugin({ options here});
$('#Edit .myClass').plugin({options here});
所以代码基本相同.我想知道是否有一种方法可以让它寻找任何一个id?
Edit
I am having problems with it when I have variables for my selectors
my.selectors =
{
A: '#Create',
B: '#Edit',
Plugin: ' .Plugin'
};
$(selector.A+ selectors.Plugin, selector.B+ selectors.Plugin)
似乎没有跑.