来自< select>的值选项到跨度CSS类 [英] Value from <select> options to a span CSS class
问题描述
我一直在努力让这个工作几天了。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);
})
这篇关于来自< select>的值选项到跨度CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!