根据jQuery文档,我需要转义出现在我的选择器字符串中的元字符,当它们以文字形式出现时。但是,我找不到很多具体的例子说明什么时候以及何时不逃避选择器。因此,何时何时不需要转义元字符,何时将它们解释为文字,请参阅:我什么时候需要转义metacharectars? (jQuery选择器)
属性选择器?即
$("[attr=value]")
Id选择器?即
$("#id")
类选择器?即
$(".class");
而且,有编写替换选择字符串metachars,同时仍保留了开始字符函数的方法吗?即:
// replace all meta chars, preserving the id selection?
$("#id.rest$of*string")
// replace all meta chars, preserving the attribute selection?
// going back to my previous question, do I even need to escape the metachars in this situation?
$("[attr=blah.dee#foo*yay]")
我之所以问这个问题,是因为我正在与一个网站碰巧有一些真正讨厌的选择器。而且我无法控制网站,所以我不能改变选择器来更好地处理。
谢谢!