最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

在jquery中如何实现动态添加并获取样式名称

来源:动视网 责编:小OO 时间:2020-11-27 19:39:09
文档

在jquery中如何实现动态添加并获取样式名称

实例如下所示。,string.length));});<;/script>;。<;pre name=";code";class=";html";>;<;script type=";text/javascript";src=";http://code.jquery.com/jquery-latest.js";>;<;/script>;<;select class=";form-control";id=';selectId';>;<;option class=";all";value=";>;)。
推荐度:
导读实例如下所示。,string.length));});<;/script>;。<;pre name=";code";class=";html";>;<;script type=";text/javascript";src=";http://code.jquery.com/jquery-latest.js";>;<;/script>;<;select class=";form-control";id=';selectId';>;<;option class=";all";value=";>;)。


下面我就为大家分享一篇jquery动态添加以及遍历option并获取特定样式名称的option方法,具有很好的参考价值,希望对大家有所帮助。

实例如下所示:

<pre name="code" class="html"><script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<select class="form-control" id='selectId'> 
<option class="all" value="0">全部</option> 
<option class="all" value="1">os2</option> 
<option>os2-anthonos</option> 
<option>os2-apps</option> 
<option>os2-centralpoint</option> 
<option>kf5-experimental</option> 
</select> 
<script> 
 //动态添加option 
 //$("#selectId").append("<option value='"+value+"'>"+text+"</option>"); 
 $(document).ready(function(){ 
 var string = ""; 
 $("#selectId option").each(function(){ //遍历全部option 
 var text = $(this).text(); //获取option的text 
 var value = $(this).val(); //获取option的value 
 if($(this).attr("class")=="all") 
 string +="{"+text+":"+value+"}"; 
 }); 
 alert(string.substring(0,string.length)); 
}); 
</script>

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

在微信小程序中如何实现多文件下载

在JavaScript中如何实现读取和写入cookie

如何看待vue中的深复制

在微信小程序中如何使用switch组件

在vue中如何导入swiper插件?

通过微信小程序如何实现手势图案锁屏

在jQuery中有关NProgress.js加载进度插件使用方法

在jQuery中有关NProgress.js加载进度插件使用方法

文档

在jquery中如何实现动态添加并获取样式名称

实例如下所示。,string.length));});<;/script>;。<;pre name=";code";class=";html";>;<;script type=";text/javascript";src=";http://code.jquery.com/jquery-latest.js";>;<;/script>;<;select class=";form-control";id=';selectId';>;<;option class=";all";value=";>;)。
推荐度:
标签: 如何 样式 jQuery
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top