我如何......在多选中更改颜色 [英] How do I... Change color on multiselect
本文介绍了我如何......在多选中更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
我试图改变多个元素的颜色,即列
但它确实没有工作
我尝试过:
Here is my code
I m trying to change colour of mutiple elements i.e. columns
but it does nt work
What I have tried:
<table>
<tr>
<td class="bd" id="Green">
<div>Green</div>
</td>
<td class="bd" id="Blue">
<div>Blue</div>
</td>
<td class="bd" id="Yellow">
<div>Yellow</div>
</td>
<td class="bd" id="Red">
<div>Red</div>
</td>
<td>
<select multiple id="sel">
<option value='Please'>---Please Select---</option>
<option value='Green'>Green</option>
<option value='Blue'>Blue</option>
<option value='Yellow'>Yellow</option>
<option value='Red'>Red</option>
</select>
</td>
</tr>
</table>
<style>
.bd
{
border:1px solid;color:black;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
jQuery("#sel").change(function()
{
$color=jQuery('#sel').val();
jQuery('#'+$color).css('background',$color);
jQuery('#'+$color).css('color','white');
if($color=="Please")
{
jQuery('.bd').css('background','');
jQuery('.bd').css('color','');
}
});
});
</script>
推荐答案
(document).ready(function(){
jQuery( #sel)。change(function()
{
(document).ready(function(){ jQuery("#sel").change(function() {
color = jQuery('#sel')。val();
jQuery('#'+
color=jQuery('#sel').val(); jQuery('#'+
color).css('background',
color).css('background',
这篇关于我如何......在多选中更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文