删除类选择选项未选中 [英] Remove a class select option is not selected

查看:86
本文介绍了删除类选择选项未选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从选择框中选择内容时,它通过这种方式向

When i select something from a selectbox it adds a class to the

选择选项添加一个类:

$('div#tabs input [type =text],select option:selected,input:checked,

textarea')。addClass('takethis');
但是当我选择一个不同的选项,它不会从我首次选择的选项中删除类
'takethis'。
如何强制这个?

selected option this way: $('div#tabs input[type="text"], select option:selected, input:checked, textarea').addClass('takethis'); But when i select a different option it doesn't remove the class 'takethis' from the option which I first selected. How can I force this?

推荐答案

从所有未选择的选项中删除类:

Remove class from all non-selected options:

$("select option:not(:selected)").removeClass("takethis");

然后添加到选定的一个:

Then add to selected one:

$("select option:selected").addClass("takethis");

这篇关于删除类选择选项未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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