js下拉框选择图片
二种方式:下拉框里面选项有图片与没有图片
1.用下拉框写 下拉框的option没法添加图片如果下拉框里面不需要图片可以用这种方式。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
img{
width:25px;
}
</style>
</head>
<body>
<img src="img/index.png"/>
<select >
<option value="img/index.png">首页</option>
<option value="img/logo.png">动漫</option>
<option value="img/select.png">电影</option>
<option value="img/loading.gif">博客</option>
</select>
<script>
var main=document.querySelector("select");
var img=document.querySelector("img");
main.onchange=function(){
img.setAttribute("src",this.value);
}
</script>
</body>
</html>
2.用列表模拟下拉框 下拉框里面需要图片可以用这种方式。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 250px;
}
.box-item{
height: 50px;
line-height: 50px;
}
.box-item img{
width: 25px;
vertical-align: middle;
}
ul{
display: none;
width: 100%;
list-style: none; }
li{
height: 30px;
line-height: 30px;
}
li:hover{
background: #FFC0CB;
}
li img{
width:25px;
vertical-align: middle;
} </style>
</head>
<body>
<div class="box">
<div class="box-item">
<img src="img/index.png"/>
请选择
</div>
<ul>
<li>
<img src="img/index.png"/>
首页
</li>
<li>
<img src="img/logo.png"/>
首页1
</li>
<li>
<img src="img/index.png"/>
首页2
</li>
</ul> </div>
<script>
var ul = document.querySelector("ul"); var boxContent = document.querySelector(".box-item");
//点击下拉框显示并阻止冒泡,防止触发document上写的隐藏下拉框函数
boxContent.onclick = function(e) {
var e = e || window.event;
ul.style.display = "block";
e.stopPropagation();
};
//选择选项替换你内容,并隐藏
for(var i=0;i<li.length;i++){
li[i].onclick=function(){
boxContent.innerHTML =this.innerHTML;
ul.style.display = "none";
}
}
//点击document隐藏下拉框 选择框显示但不做选择时点击页面选择框隐藏
document.onclick = function() {
ul.style.display = "none";
}
</script>
</body>
</html>
js下拉框选择图片的更多相关文章
- 将select的默认小三角替换成别的图片,且实现点击图片出现下拉框选择option
最近做项目,要求修改select下拉框的默认三角样式,因为它在不同浏览器的样式不同且有点丑,找找网上也没什么详细修改方法,我就总结一下自己的吧. 目标是做成下图效果: 图一:将默认小三角换成红圈的三角 ...
- 前端下拉框选择和动态生成调用div
进入到一个项目期中,一边做项目,一边学习其中用到的知识.这些知识都是零碎的,有数据库,有html,有js,还有django.趁周末时间,整理前面遇到过的前端相关的知识点. 下拉框选择 <html ...
- js下拉框二级关联菜单效果代码具体实现
这篇文章介绍了js下拉框二级关联菜单效果代码具体实现,有需要的朋友可以参考一下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...
- Python+selenium之获取文本值和下拉框选择数据
Python+selenium之获取文本值和下拉框选择数据 一.结合实例进行描述 1. 实例如下所示: #新增标签操作 def func_labels(self): self.driver.find_ ...
- 使用 jQuery 实现页面背景色的更换,通过下拉框选择对应的颜色,页面背景会随着选中的颜色进行更换
查看本章节 查看作业目录 需求说明: 使用 jQuery 实现页面背景色的更换,通过下拉框选择对应的颜色,页面背景会随着选中的颜色进行更换 实现思路: 在页面中添加 <select> 标签 ...
- js下拉框
Js下拉框 http://sc.chinaz.com/tag_jiaoben/XiaLaKuang.html
- select下拉框选择触发事件
我一直以来都认为,select 下拉框选择对选项 options 使用 onclick 注册事件即可,如下: <select> <option value="0" ...
- PHP下拉框选择的实现方法
实现 第一种PHP下拉框实现方法: < ?php //提交下拉框; //直接饱触发onchange事件的结果 $id=$_GET['myselect']; // myselect 为locati ...
- Selenium 3----警告框处理+下拉框选择
警告框处理 在WebDriver中处理JavaScript所生成的alert.confirm以及prompt十分简单,具体做法是使用 switch_to.alert 方法定位到 alert/confi ...
随机推荐
- Dango之视图函数
1.request对象 HTTPRequest对象就是咱们的视图函数的参数request def home(request): print(request) #<WSGIRequest: GET ...
- sql server isnull函数
isnull函数 --ISNULL() 函数用于规定如何处理 NULL 值 语法:SELECT ISNULL(check_expression, replacement_value) --check_ ...
- EJS学习(五)之EJS的CommonJs规范版本
EJS的CommonJs规范版本 ejs分为两个版本一个是CommonJs版本,另外一个是AMD规范的版本. 基础:html页面 安装:<script type="text/javas ...
- java实现spark常用算子之frist
import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...
- Hadoop学习之 HIVE 多用户模式安装
一.启动hadoop 集群 1.启动zookeeper 集群 zkServer.sh start 2.在master.hadoop 机器上 ./start-all.sh 由于 start-all命 ...
- hiper、sitespeed性能工具
https://github.com/pod4g/hiper hiper: A statistical analysis tool for performance testing https: ...
- HTML 5的革新之一:语义化标签一节元素标签。
摘至于:<HTML 5的革新——语义化标签(一)> HTML 5的革新之一:语义化标签一节元素标签. 在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义.(即 ...
- SuperMap webgl对接iportal托管的三维服务
在webgl中对接iportal加密的三维服务时,需要提前注册key值.Cesium.Credential.CREDENTIAL = new Cesium.Credential("你的key ...
- python cv2读取rtsp实时码流按时生成连续视频文件
代码实现 # coding: utf-8 import datetime import cv2 import os ip = '192.168.3.160'.replace("." ...
- LInux安装MySQL5.7.24详情
安装包下载 MySQL 的官网下载地址:http://www.mysql.com/downloads/ 我安装的是5.7版本 第二步: 选择:TAR (mysql-5.7.24-el7-x86_64. ...