根据select的data-*属性更改图片img的src链接JQ实例,直接上实例代码:
- <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>