jquery点击按钮弹出图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="js/jquery-3.4.1.min.js"></script>
<title>Document</title>
<style>
.bor{
border: 2px solid red;
width: 400px;
height: 200px;
text-align: center;
}
#main {
margin-top: 50px;
border: 1px solid black;
cursor: pointer;
padding: 30px;
}
#qrcode img {
position: absolute;
top: 50%;
left: 40%;
width: 300px;
height: 300px;
display: block;
}
#qrcode {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.6);
z-index: 9999;
display: none;
}
</style>
</head>
<body>
<div class="bor">
<button class="main">点击此处 弹出你想要的</button>
<div class="qrcode">
<img class="image" width="100%" height="100%" src="img/12.png">
</div>
</div>
<div class="bor">
<button class="main">点击此处 弹出你想要的</button>
<div class="qrcode">
<img class="image" width="100%" height="100%" src="img/12.png">
</div>
</div>
<script>
//当本页面有两个按钮点击事件的时候,不适合用id(因为id是唯一的),需要把id换为class,最为简单的修改方法;
// 这样才会是实现你想要的效果,点击按钮弹出图片
$(function() {
$(".main").click(function() {
$(".qrcode").fadeIn("slow");
});
$(".qrcode").click(function() {
$(".qrcode").fadeOut("slow");
})
});
//该段代码适合本页面只有一个按钮点击
$(function() {
$("#main").click(function() {
$("#qrcode").fadeIn("slow");
});
$("#qrcode").click(function() {
$("#qrcode").fadeOut("slow");
})
});
</script>
</body>
</html>
以上是运用jquery里面的fade()函数写的点击事件。
下面这个是用传统的onclick写出来的,有一点点小问题,刚开始是有效的,今天重新写出来之后不知道为什么没效果了,大家可以帮我看下,我也发布出来
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="js/jquery-3.4.1.min.js"></script>
<title>Document</title>
<style>
.bor{
border: 2px solid red;
width: 400px;
height: 200px;
text-align: center;
}
#main {
margin-top: 50px;
border: 1px solid black;
cursor: pointer;
padding: 30px;
}
#qrcode img {
position: absolute;
top: 50%;
left: 40%;
width: 300px;
height: 300px;
display: block;
}
#qrcode {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.6);
z-index: 9999;
display: none;
}
</style>
</head>
<body>
<div class="bor">
<button id="main">点击此处 弹出你想要的</button>
<div id="qrcode">
<img id="image" onclick="test(this)" width="100%" height="100%" src="img/12.png">
</div>
</div>
<div class="bor">
<button id="main">点击此处 弹出你想要的</button>
<div id="qrcode">
<img id="image" onclick="test(this)" width="100%" height="100%" src="img/12.png">
</div>
</div>
<script>
// 传统的方法来写,onclick
function test(obj){
console.log("11111")
$(obj).next().fadeIn("slow");
$(obj).next().click(function() {
$(this).fadeOut("slow");
})
var hh = $(obj).next().html();
console.log(hh)
}
</script>
</body>
</html>
jquery点击按钮弹出图片的更多相关文章
- jquery实现点击按钮弹出层和点击空白处隐藏层
昨天做项目遇到一个问题,和大家分享下,jquery实现点击按钮弹出层和点击空白处隐藏层的问题 if($('.autoBtn').length){ $('.autoBtn' ...
- ExtJs 4.2.1 点击按钮弹出表单的窗口
初学ExtJs,做项目的时候想做一个这样的效果:点击按钮弹出对话框,之前一直是使用EasyUi来做的, EasyUi里有Dialog,用起来很方便,但是现在转移到ExtJs上后,发现没有Dialog这 ...
- JavaScript实现点击按钮弹出输入框,点确定后添加li组件到ul组件里
JavaScript实现点击按钮弹出输入框,点确定后添加li组件到ul组件里 <!doctype html> <html manifest="lab4.manifest&q ...
- 请写出一段JavaScript代码,要求页面有一个按钮,点击按钮弹出确认框。程序可以判断出用
请写出一段JavaScript代码,要求页面有一个按钮,点击按钮弹出确认框.程序可以判断出用 户点击的是“确认”还是“取消”. 解答: <HTML> <HEAD> <TI ...
- Html : 点击按钮弹出输入框,再次点击进行隐藏
上代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- jQuery第三课 点击按钮 弹出层div效果
jQuery 事件方法 事件方法会触发匹配元素的事件,或将函数绑定到所有匹配元素的某个事件. 触发实例: $("button#demo").click() 上面的例子将触发 id= ...
- 点击按钮弹出一个div层
JQuery弹出层,点击按钮后弹出遮罩层,还有关闭按钮 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml& ...
- ASP.NET点击按钮弹出确认对话框方法
开发asp.net网页应用程序的时候,有些页面的按钮需要增加一个确认对话框,比如: 实现这个功能比较简单,代码这样写: Button.Attributes["onclick"] = ...
- Asp.net点击按钮弹出文件夹选择框的实现(网页)
本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092112.html 在Asp.net网站实际的开发中,比如:需要实现点击一个类似于FileUpload的 ...
随机推荐
- Oracle的优化
Oracle优化:物理优化和逻辑优化.物理优化:1):Oracle的运行环境.2):合理的使用优化器.3):合理配置Oracle实例参数4):建立合适的索引(减少IO)5):将索引数据和表数据分开在不 ...
- redis过期策略设置
中6中过期策略的具体方式. redis 中的默认的过期策略是volatile-lru .设置方式 可以通过命令直接设置 config set maxmemory-policy volatile-lru ...
- HDU 6581 Vacation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission( ...
- Laya layout算法
/** * <p>重置对象的 <code>X</code> 轴(水平方向)布局.</p> * @private */ public function r ...
- 高级软件测试技术(测试管理工具实践day1)
今天进行了班级内部各小组选择测试工具,选择各自需要进行测试管理工具.我们小组暂定选择 禅道 但是班级内其他小组选择的工具还没确定,还没进行
- The JavaScript this Keyword
https://www.w3schools.com/js/js_this.asp What is this? The JavaScript this keyword refers to the obj ...
- Idea导入项目详解
1.点击Import Project选择项目所在目录 2.Import Project选项区别: 1)如果选择Create project from existing sources选项, 则你只能导 ...
- python-笔记(三)文件操作
文件的操作一般分三步: 1.打开文件,获取文件的指针(句柄) 2.通过指针(句柄)操作文件 3.关闭文件 现在有以下文件: 我们为爱还在学 学沟通的语言 学着谅解 学着不流泪 等到我们学会飞 飞越黑夜 ...
- Linux_ISCSI服务器
目录 目录 网络存储 ISCSI How to setup ISCSI server SCSI Commands Server Side Client Side Edit the ISCSI conf ...
- Jmeter之JDBC--Mysql
一.添加JDBC Connection Configuration控件 界面显示如下: 配置说明: 1.名称:标识 2.注释:备注信息 3.Variable Name:定义的变量名,供后续调用: 4. ...