直接上实例代码:
<img id="brandIcon" src="" /> <script language="JavaScript" type="text/javascript" > function setBeerIcon() { var classimg = $("#beer").find("option:selected").attr('data-img'); $("#brandIcon").attr("src",classimg); } </script> <form> <select id="beer" onChange="setBeerIcon();"> <option value="1" data-img="/images/1.jpg">项目一</option> <option value="2" data-img="/images/2.jpg">项目二</option> <option value="3" data-img="/images/3.jpg">项目三</option> </select> </form>
查看原内容