jquery 获取 html 标签的 class 值

news/2024/7/10 23:24:03 标签: html5, css, class, jquery
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">
class="line mt-10 q-content" style="margin-top:10px; margin-bottom:0px; padding:0px; font-family:arial,'courier new',courier,宋体,monospace; white-space:pre-wrap; word-wrap:break-word; word-break:break-all; color:rgb(51,51,51); font-size:14px; line-height:24px">比如 <div class="home current">home</div> 这个 div 的class 里两个值一个是 home 一个是 current,现在我想要 jquery 只获取其中的一个,通过某种方法只返回 home 或是 class,如何实现?
class="line mt-10 q-content" style="margin-top:10px; margin-bottom:0px; padding:0px; font-family:arial,'courier new',courier,宋体,monospace; white-space:pre-wrap; word-wrap:break-word; word-break:break-all; color:rgb(51,51,51); font-size:14px; line-height:24px">
class="line mt-10 q-content" style="margin-top:10px; margin-bottom:0px; padding:0px; font-family:arial,'courier new',courier,宋体,monospace; white-space:pre-wrap; word-wrap:break-word; word-break:break-all; color:rgb(51,51,51); font-size:14px; line-height:24px">
class="best-text mb-10" style="margin-top:0px; margin-bottom:10px; padding:0px; font-family:arial,'courier new',courier,宋体,monospace; white-space:pre-wrap; word-wrap:break-word; color:rgb(51,51,51); font-size:14px; line-height:24px; background-color:rgb(241,254,221)">var val=$("div").attr("class");//这里获取class值
var array=val.split(" ");//split双引号里面是空格,把class值用空格分开,转换为数组
那么,array[0]就获得home; arrya[1]获得class


http://www.niftyadmin.cn/n/1335537.html

相关文章

如何把mp4视频转换成gif动态图

提到gif动态图想必大多数小伙伴即便是不熟悉也肯定也不会陌生的。近几年来随着“表情包”的流行和井喷式的发展使表情包成为了新兴的网络语言。而gif动态图由于表达效果更加强烈且表达效果更加明显也随之火爆起来。而有小伙伴就问过我好几次如何把mp4视频转gif动态图。下面就来…

[PHP] yield沟通函数循环内外

1.yield是函数内外,循环内外沟通用的 , 当你的函数需要返回一个大数组 , 循环的时候需要遍历这个大数组时 , 并且需要多次遍历这个函数的返回值 , 这个是有用的 2.当我也是只需要在一次循环中就可以处理完所有的事情时 , 这个就没啥用 <?php $startmemory_get_usage();func…

6大顶级自学资源网站!不甘现状,学无止境

俗话说得好&#xff0c;下班后的时间决定你最终的高度&#xff0c;明个儿就是周一啦&#xff0c;希望亲们在完成日常工作的同时&#xff0c;不要忘了不断提升自己&#xff0c; 你要坚信&#xff01;只有坚持自学&#xff0c;才能最快的升职加薪啊&#xff01; 01- 可汗学院 非…

ie不支持getElementsByClassName,所以要自己实现获取类名为className的所有元素。

<html><head><script type"text/javascript">window.onload function(){ var topMenus getClass(li,topMenu);for(var i0;i < topMenus.length; i){alert(topMenus[i].innerHTML); }}function getClass(tagName,className) //获得标…

webstorm TFS 插件的安装与使用(1)

在工作中遇到的问题&#xff0c;我们公司使用webstorm 做开发&#xff0c;进行版本控制的时候自然要用到相关的插件&#xff0c;我们使用的是TFS 插件&#xff0c;那时候翻遍百度都没找到几篇教程&#xff0c;很尴尬&#xff0c;最后还是在公司同事的指导下熟悉使用的。在这里做…

点击按钮打开一个新的窗口 关键词(Intent, setData , putExtra , startActivity |Bundle)

M3U8_Video_demo 项目 //------------------ 创建发送private void playVideo(String source, String title) { if (source null || source.equals("")) { Toast.makeText(this, "视频内容不存在&#xff01;", Toast.LENGTH_LONG).show(); …

Activity2---使用

1封装 baseActivity封装方式 2启动配置 taskAffinity taskAffinity用于指定当前Activity(activity1)所关联的Task&#xff0c;allowTaskReparenting用于配置是否允许该activity可以更换从属task&#xff0c;通常情况二者连在一起使用&#xff0c;用于实现把一个应用程序的A…

Activity3---不经意的死掉onSaveInstanceState

android onSaveInstance方法 1周期 注&#xff1a;2使用场景&#xff1a; a来电话b照相c横竖屏dhome键盘e电源键f新启动activity3使用示例 Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // save the current data, …