使用jQuery获取字符串的子字符串 [英] Obtain a substring of a string using jQuery

查看:142
本文介绍了使用jQuery获取字符串的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  form-group val-presence-text val-type-pos- int val-length-10 has-success has-feedback 

我想获取 10 来自 val-length-10 类名称。我尝试了各种方法,但没有一个适用于像这样的动态多类属性。另外, 10 可以是任何正整数,并且类可以位于类组中的任何位置。



任何想法?

解决方案

您可以使用这个:

<$ p $ (/ var-length-(\ d +)/)[1];

var val_length = $('div')。attr(class


I have a div with the following classes:

form-group val-presence-text val-type-pos-int val-length-10 has-success has-feedback

I want to get the 10 from the val-length-10 class name. I've tried various methods, but none seem to work for a dynamic multi-class attribute such as this. In addition, the 10 could be any positive integer and the class could be located anywhere within the group of classes.

Any ideas?

解决方案

You can use this:

var val_length = $('div').attr("class").match(/val-length-(\d+)/)[1];

这篇关于使用jQuery获取字符串的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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