jquery选择并使用类名的一部分 [英] jquery select and use part of class name

查看:152
本文介绍了jquery选择并使用类名的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多班以 edit _ 开头。我用 [class ^ =edit _] 为他们打样。现在,每个类都有不同的数字,如 edit_20 edit_80 edit_150 。如何剥离类名的第一部分( edit _ ),以便如果将其传递给变量,它将只包含数字?

I have a lot of classes who starts with edit_. I've styled them with [class^="edit_"]. Now, each class have a different number like edit_20 edit_80 edit_150. How can i strip the first part of the class name (edit_) so that if passing it to a variable, it will only contain the number?

推荐答案

尝试 .split() $ c> _ 并从返回的数组中获取第二个元素。

Try to .split() it out with _ and get the second element from the returned array.,

var number = "edit_20".split('_')[1];

这篇关于jquery选择并使用类名的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆