JS動態,有選擇性的改變div顏色


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM