码迷,mamicode.com
首页 > Web开发 > 详细

JS动态,有选择性的改变div颜色

时间:2015-04-05 17:11:27      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

JS代码:

<script language="javascript">
function check(value)
{
document.getElementById(value).style.background= "black";
}
</script>

 

div处部分代码:

<div id="1" style=" color:#FFF; width:40px; height:40px; float:left; margin-right:10px; text-align:center;line-height:40px;">1</div>
<div id="2" style=" color:#FFF; width:40px; height:40px; float:left; margin-right:10px; text-align:center;line-height:40px;">2</div>
<div id="3" style=" color:#FFF; width:40px; height:40px; float:left; margin-right:10px; text-align:center;line-height:40px;">3</div>
<div id="4" style=" color:#FFF; width:40px; height:40px; float:left; margin-right:10px; text-align:center;line-height:40px;">4</div>
<div id="5" style=" color:#FFF; width:40px; height:40px; float:left; margin-right:10px; text-align:center;line-height:40px;">5</div>

 

radio处部分代码,使用onclick()函数调用check(),并加入参数,使得与参数相应的div颜色改变:

<div class="col-lg-12">
<p class="question-content">
<input type="radio" name="optionsRadios1" id="optionsRadios1" value="option1" onclick="check(1);">
A. 220\(\rm{V}\)、10\(\rm{A}\) 
</p>
</div>

 

JS动态,有选择性的改变div颜色

标签:

原文地址:http://www.cnblogs.com/ericren/p/4394327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!