来自< select>的值选项到跨度CSS类 [英] Value from <select> options to a span CSS class

查看:95
本文介绍了来自< select>的值选项到跨度CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力让这个工作几天了。flabbergasted。我不是JavaScript / jQuery AT ALL的专家,所以很容易,哈哈。 ; - )

I've been trying to get this working for a few days now.. flabbergasted. I'm not an expert on JavaScript/jQuery AT ALL, so go easy, haha. ;-)

我有一个9个值的下拉列表。我也有一个班级设置为'option0'的跨度。下拉菜单显然具有从1到9的值。当下拉列表改变时,我想更改跨度的类别。如果使用下拉列表并选择了选项5,我希望跨度具有类'option5'。

I have a dropdown with 9 values. I also have a span with a class set to 'option0'. The dropdown obviously has values ranging from 1 to 9. I want to change the class of the span when the dropdown is changed as well. If the dropdown is used and option 5 is selected, I want the span to have class 'option5'.

这样做最好的方法是什么?感谢您的阅读,希望能尽快收到您的回复。

What would be the best way of doing this?

c:

推荐答案

$('select').change(function(){
   var val = $(this).val();
   alert(val);
   $('span').removeAttr('class').addClass('option' + val);
})

http://jsfiddle.net/SAy7W/1/

这篇关于来自< select>的值选项到跨度CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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