select下面option的選中下標selectedIndex


<img id='pic' src='http://oi5k7c9bd.bkt.clouddn.com/log_yuan.png'/>
<select id='sel' onchange="showImg()">
    <option value='http://oito4x28c.bkt.clouddn.com/mmexport1470584347994.jpg'>圖片1</option>
    <option value='http://oito4x28c.bkt.clouddn.com/mmexport1470235530625.jpg'>圖片2</option>
    <option value='http://oito4x28c.bkt.clouddn.com/mmexport1475076387668.jpg'>圖片3</option>
</select>
<script>
  function showImg () {
    var oSelect = document.getElementById('sel');
    var index = oSelect.selectedIndex;   //option數組返回的同時會返回當前option的選中下標selectedIndex
document.getElementById(
'pic').src = oSelect[index].value;
}
</script>

 


免責聲明!

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



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