[英]How to show D3 chart using Bootstrap modal popup when click on button and download it as image format
[英]Show image in a popup when I click button
我有一个按钮,当我单击此按钮时,我需要在弹出窗口中显示图像。
为什么这段代码不起作用? 我尝试在onclick
事件中使用 window.open 但它不起作用
<input type="button" value="Mostra Immagine" onclick=window.open(src="../img/mypicture.jpg")>
我的错误在哪里?
你可以使用fancybox来做到这一点。
a { color: #FFFFFF; text-decoration: none; } .primary-btn { background-image: -moz-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%); background-image: -webkit-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%); background-image: -ms-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%); } .primary-btn { line-height: 36px; padding-left: 30px; padding-right: 30px; border-radius: 25px; border: none; color: #fff; display: inline-block; font-weight: 500; position: relative; -webkit-transition: all 0.3s ease 0s; -moz-transition: all 0.3s ease 0s; -o-transition: all 0.3s ease 0s; transition: all 0.3s ease 0s; cursor: pointer; text-transform: uppercase; position: relative; } .primary-btn { color: #fff; border: 1px solid #fff; -webkit-transition: all 0.3s ease 0s; -moz-transition: all 0.3s ease 0s; -o-transition: all 0.3s ease 0s; transition: all 0.3s ease 0s; } .primary-btn:hover { background: transparent; color: #235ee7; border-color: #235ee7; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.0/jquery.fancybox.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.0/jquery.fancybox.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.0/jquery.fancybox.min.css"> <a data-fancybox="gallery" class="primary-btn" href="//source.unsplash.com/user/erondu/300x300">Demo</a>
您在 onclick 中缺少"
并为新页面添加_blank
。使用'
引号将参数与 in 函数一起传递
<input type="button" value="Mostra Immagine" onclick="window.open('../img/mypicture.jpg','_blank')">
您使用的属性和函数是错误的:
onclick="window.open('../img/mypicture.jpg');"
总是引用一个属性值,就像你对type
和value
所做的那样。
而且window.open
函数需要一个路径,不需要写“src=”。
MDN - window.open()
试试这个:
HTML:
<div class="popup" onclick="myFunction()">Click me!
<span class="popuptext" id="myPopup">Popup text...</span>
</div>
CSS:
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
JavaScript:
<script>
// When the user clicks on <div>, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
</script>
你可以在这里阅读更多https://www.w3schools.com/howto/howto_js_popup.asp希望有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.