简体   繁体   English

我试图让图像出现 onclick,并且脚本没有执行

[英]I am trying to make image appear onclick, and the script is not executing

I'm trying to make a separate image appear when you click an active image on a page.当您单击页面上的活动图像时,我正在尝试显示单独的图像。

I've tried moving the onclick into the <a> tag, the <img> tag, the <div> tag, I've tried using different versions of this script command, nothing will seem to make it work.我尝试将 onclick 移动到<a>标记、 <img>标记、 <div>标记中,我尝试使用此脚本命令的不同版本,但似乎没有任何效果。 The active images and the cursor:pointer all work, but the java is failing.活动图像和 cursor:pointer 都可以工作,但 java 失败。 Any ideas??有任何想法吗??

 function opencontact() { var x = document.getElementById("instagram"); if (x.style.display === "none") { x.style.display = "inline"; } else { x.style.display = "none"; } }
 .insta { display: none; position: fixed; top: 180px; right: 220px; z-index: 2; transition: 0s; padding: 0px; }
 <div id="lips2" class="lipbtn2"> <span style="cursor:pointer" onclick="opencontact()"> <a> <img src="https://www.country935.ca/wp-content/uploads/sites/19/2017/07/a-kiss.jpg" width="15%" height="auto" alt="" class="kiss2"> <img src="https://dzasv7x7a867v.cloudfront.net/product_photos/34277616/20150910_011229_1000w.png" width="15%" height="auto" alt="" class="kiss2active"> </a> </span> </div> <div id="instagram" class="insta"> <a href="http://instagram.com/"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Instagram_logo_2016.svg/1200px-Instagram_logo_2016.svg.png" alt="" width="124px" /> </a> </div>

You need to turn the test around or you will have to click twice您需要翻转测试,否则您将不得不单击两次

I am not sure what else you want to happen我不确定你还想发生什么

 function opencontact() { var x = document.getElementById("instagram"); x.style.display = x.style.display === "inline"? "none": "inline" }
 .insta { display: none; position: fixed; top: 180px; right: 220px; z-index: 2; transition: 0s; padding: 0px; }
 <div id="lips2" class="lipbtn2"> <span style="cursor:pointer" onclick="opencontact()"> <a> <img src="https://www.country935.ca/wp-content/uploads/sites/19/2017/07/a-kiss.jpg" width="15%" height="auto" alt="" class="kiss2"> <img src="https://dzasv7x7a867v.cloudfront.net/product_photos/34277616/20150910_011229_1000w.png" width="15%" height="auto" alt="" class="kiss2active"> </a> </span> </div> <div id="instagram" class="insta"> <a href="http://instagram.com/"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Instagram_logo_2016.svg/1200px-Instagram_logo_2016.svg.png" alt="" width="124px" /> </a> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使 onclick 功能在 tr 元素中工作 - I am trying to make onclick function work in a tr element 如何使图片显示在onclick的随机位置上 - How to make an image appear on a random position onclick 向下滚动certian amont时,我试图使div出现? - I am trying to make a div appear when i scroll down a certian amont ? HTML不执行OnClick脚本 - HTML not executing OnClick script 我试图让div在点击时消失并使另一个div出现在我编写的地方并使用javascript运行代码; - I am trying to make a div disappear on click and make another div appear in its place I have wrote and run code using javascript; 如何使文字显示在Image Map区域的单独div onClick中? - How to make text appear in separate div onClick for area of Image Map? 我正在尝试制作一个事件侦听器,当您单击图像时它会显示一个 div - I'm trying to make an event listener that makes it to where when you click on an image it makes a div appear 尝试使用 Onclick 显示表格 - Trying to get a table to appear with Onclick 如何使用 Javascript 使 div 出现 onclick? - How can I make a div appear onclick using Javascript? 使用 ReactJS 和 ChakraUI 构建登录页面。 尝试使用图像,但它不会出现在页面上。 我究竟做错了什么? - Building a Login Page using ReactJS and ChakraUI. Trying to use an image but it will not appear on the page. What am I doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM