我如何获得类名(作为字符串)以“test-”开头,使用jquery? [英] How can i get the class name (as a string) that begins with "test-" using jquery?

查看:489
本文介绍了我如何获得类名(作为字符串)以“test-”开头,使用jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题真的说这一切,

如果有一个元素

<span class="a-class another-class test-top-left"></span>

如何获得类名,以test-开头到字符串变量,

how can i get the classname, beginning with "test-" into a string variable so i can then extract the top and left words from that classname into separate variables and use them.

推荐答案

var test = (​$("span[class*='test-']")[0].className​​).split("test-")​[1].split("-");

其中test [0]将包含top,test [1]将包含left。

Where test[0] will contain "top" and test[1] will contain "left".

以下是演示示例: http:// jsfiddle。 net / kayen / QJCpc /

这篇关于我如何获得类名(作为字符串)以“test-”开头,使用jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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