Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
任何类中字符串的Jquery Relace部分_Jquery - Fatal编程技术网

任何类中字符串的Jquery Relace部分

任何类中字符串的Jquery Relace部分,jquery,Jquery,我试图通过删除类名的结尾,为以前选择的任何链接重置一个类 单击链接时,该类将附加“_selected”,以便图像保持高亮显示。当单击另一个链接时,我正试图从以前可能已选择的任何链接(页面上的许多滚动)中删除“_selected” 似乎以下方法应该有效: $('a').attr('class').replace(/_selected/g') 这不是在查找所有带有类的链接并将“\u selected”的实例替换为空吗 有没有更好的方法来看待这个问题?jQuery的新功能。。。谢谢您可以在一个元素中放

我试图通过删除类名的结尾,为以前选择的任何链接重置一个类

单击链接时,该类将附加“_selected”,以便图像保持高亮显示。当单击另一个链接时,我正试图从以前可能已选择的任何链接(页面上的许多滚动)中删除“_selected”

似乎以下方法应该有效:

$('a').attr('class').replace(/_selected/g')

这不是在查找所有带有类的链接并将“\u selected”的实例替换为空吗


有没有更好的方法来看待这个问题?jQuery的新功能。。。谢谢

您可以在一个元素中放置多个类,如:

<a class="someClass selected" />
当然,之前您已经添加了

$("your-selector").addClass("selected");
当然,你需要定义它

<style>
 A.selected {
     /*your styles here*/
 }
</style>
$('a').attr('class')将为每个jQuery'a'元素返回'class'字符串,而不是元素本身

我认为你应该这样做:

$('a')。每个(函数(){

$(this.attr('class',$(this.attr('class')).replace(/_selected/g')


}))

多类选项在这种情况下工作得很好。我都没想到。多谢!
<style>
 A.selected {
     /*your styles here*/
 }
</style>
$("a").each(function(){
    $(this).attr("class", $(this).attr("class").replace(/_selected/g,""));
});