如何检查body是否具有JavaScript的特定类?

如何检查body是否具有JavaScript的特定类?

问题描述:

如何检查身体是否有特定的课程?
这是我的情况:

How can I check if body has specific class? This is my case:

<body class="foo foo1 foo3"></body>


function hasClass(ele,cls) {
     return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

if(hasClass(document.getElementById("test"), "test")){//do something};

也许这可以帮到你: - )

maybe this helps you :-)

使用jQuery会更容易,更少的代码但是没关系!

With the use of jQuery it would be easier and less code but nevermind !