JavaScript点击事件——美女合集
Js点击事件——美女合集
实例
效果如下图:
代码如下:
<!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">
<title>Js 美女合集</title>
<style>
* {
padding: 0;
margin: 0;
}
body{
background: #000;
}
.parent {
width: 500px;
margin: 20px auto;
}
.parent .pic {
width: 100%;
height: 400px;
}
.parent .pic img {
width: 100%;
height: 100%;
}
.box {
display: flex;
}
.box div {
flex: 1;
text-align: center;
line-height: 100px;
color: #fff;
}
.box div input {
width: 80px;
height: 30px;
border-radius: 5px;
}
#txt{
color: red;
font-size: 24px;
}
</style>
</head>
<body>
<div class="parent">
<div class="pic">
<img src="1.jpg" alt="" id="pic">
</div>
<div class="box">
<div>
<input type="button" value="上一张" id="btnLast">
</div>
<div>
第 <span id="txt">1</span> 张
</div>
<div>
<input type="button" value="下一张" id="btnNext">
</div>
</div>
</div>
<script>
var index = 1;
document.getElementById("btnNext").onclick = function () {
if (index < 14) {
index++;
}
document.getElementById("txt").innerHTML=index;
document.getElementById("pic").src = index + ".jpg";
};
document.getElementById("btnLast").onclick = function () {
if (index > 1) {
index--;
}
document.getElementById("txt").innerHTML=index;
document.getElementById("pic").src = index + ".jpg";
};
</script>
</body>
</html>
定义和用法
onclick 事件会在对象被点击时发生。
请注意, onclick 与 onmousedown 不同。单击事件是在同一元素上发生了鼠标按下事件之后又发生了鼠标放开事件时才发生的。
语法
HTML 中:
<element onclick="SomeJavaScriptCode">
JavaScript 中:
object.onclick=function(){SomeJavaScriptCode};
支持该事件的 HTML 标签:
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>,
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>,
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>,
<li>, <map>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>,
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>,
<thead>, <tr>, <tt>, <ul>, <var>
支持改事件的 JavaScript 对象:
button, document, checkbox, link, radio, reset, submit
实例
代码如下:
<!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">
<title>Js 美女合集</title>
<style>
* {
padding: 0;
margin: 0;
}
body{
background: #000;
}
.parent {
width: 500px;
margin: 20px auto;
}
.parent .pic {
width: 100%;
height: 400px;
}
.parent .pic img {
width: 100%;
height: 100%;
}
.box {
display: flex;
}
.box div {
flex: 1;
text-align: center;
line-height: 100px;
color: #fff;
}
.box div input {
width: 80px;
height: 30px;
border-radius: 5px;
}
#txt{
color: red;
font-size: 24px;
}
</style>
</head>
<body>
<div class="parent">
<div class="pic">
<img src="1.jpg" alt="" id="pic">
</div>
<div class="box">
<div>
<input type="button" value="上一张" id="btnLast">
</div>
<div>
第 <span id="txt">1</span> 张
</div>
<div>
<input type="button" value="下一张" id="btnNext">
</div>
</div>
</div>
<script>
var index = 1;
var txt=document.getElementById("txt");
var pic= document.getElementById("pic");
document.getElementById("btnNext").onclick = function () {
if (index < 14) {
index++;
}
txt.innerHTML=index;
document.getElementById("pic").src = index + ".jpg";
};
document.getElementById("btnLast").onclick = function () {
if (index > 1) {
index--;
}
txt.innerHTML=index;
pic.src = index + ".jpg";
};
</script>
</body>
</html>
运行效果如下图:
持续更新,欢迎大家指教!
JavaScript点击事件——美女合集的更多相关文章
- Javascript 语言精粹 代码片段合集
Javascript 语言精粹 代码片段合集 标签:Douglas-Crockford Javascript 最佳实践 原文链接 更好的阅读体验 使用一个method 方法定义新方法 Function ...
- 大量Javascript/JQuery学习教程电子书合集
[推荐分享]大量Javascript/JQuery学习教程电子书合集,送给有需要的人 不收藏是你的错^_^. 经证实,均可免费下载. 资源名称 资源大小 15天学会jQuery(完整版).pd ...
- CSS伪类选择器active模拟JavaScript点击事件
一.说明 设置元素在被用户激活(在鼠标点击与释放之间发生的事件)时的样式. IE7及更早浏览器只支持a元素的:active,从IE8开始支持其它元素的:active. 另:如果需要给超链接定义:访问前 ...
- JavaScript点击事件-一个按钮触发另一个按钮
<input type="button" value="Click" id="C" onclick="Go();" ...
- JS: javascript 点击事件执行两次js问题 ,解决jquery绑定click事件出现点击一次执行两次问题
javascript 点击事件执行两次js问题 在JQuery中存在unbind()方法,先解绑再添加点击事件,解决方案为: $(".m-layout-setting").unbi ...
- EXCUTE JAVAScript点击事件
# Execute Javascript document.getElementsByClassName('chooseFile')[${index}].arguments[0].click(); # ...
- JavaScript 点击事件的三种写法
嵌入式 <button οnclick='alert("hello")'>点击按钮</button> 脚本模型 btn.onclick=function() ...
- JavaScript简易事件触发合集
1.<input id="billing" type="text" placeholder="123" onkeyup="t ...
- MUI+html5+javascript 点击事件触发页面间传值
关于如何进行页面转跳,请看 https://www.cnblogs.com/JUNELITTLEPANDA/p/15956176.html,以下跳转方法是采用的其中一种 1- 仅适用于移动端,pc端 ...
随机推荐
- Java 基础-异常处理
在 Java 中声明了很多异常类,每个异常类都表示一种运行错误.程序运行过程中发生一个可识别的运行错误时(可以找到与错误匹配的异常类,例如被除数为 0 时会触发 java.lang.Arithmeti ...
- java RMI 远程调用
1.背景 在学习代理模式的过程中接触到了远程调用,jdk有自己的RMI实现,所以这边自己实现了RMI远程调用,并记录下心得. 感受最深的是RMI和现在的微服务有点相似,都是通过"注册中心&q ...
- Iview 启动报错 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
解决 fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {}); 替换为 fs.write(fd, buf, 0, ...
- JQuery weui 中的Popup (弹出层:底部)
//弹出层(从底部) <div id="bottomb" class="weui-popup__container popup-bottom"> & ...
- [SDOI2016]征途 —— 斜率优化DP
时隔多年没有碰斜率优化了... 想当年被斜率优化虐的死去活来,现在看看...也就那样吧. Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计 ...
- Netty解码的艺术
什么是拆包/粘包: TCP 粘包/拆包: TCP 是一个“流”协议,所谓流,就是没有界限的一长串二进制数据.TCP 作为传输层协议并不了解上层业务数据的具体含义,它会根据TCP 缓冲区的实际情况进行数 ...
- Mysql UPF 安装文档
一.mysql UDF 简介: github地址: http://www.mysqludf.org/lib_mysqludf_preg 二.mysql UDF 下载地址: https://github ...
- vueStudy
目录层次: 目前学习曲线有三个前端开发,每个人有各自的目录,可以很好地对比彼此的代码. unit1 邮箱验证 用户名 数字.字母.中文 .划线不能以下划线开头 2-12位 密码验证 6-20位英文和 ...
- BUUCTF--rsa
测试文件:https://buuoj.cn/files/ed10ec009d5aab0050022aee131a7293/41c4e672-98c5-43e5-adf4-49d75db307e4.zi ...
- hash和history
location.hash="aaa" history.pushState({},'', "home") history.replaceState() hist ...