Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何允许在链接中单击svg_Javascript_Html_Css_Svg - Fatal编程技术网

Javascript 如何允许在链接中单击svg

Javascript 如何允许在链接中单击svg,javascript,html,css,svg,Javascript,Html,Css,Svg,我有以下html: <a class="delete show-modal" href="#;"> <svg x="0px" y="0px" width="12px" height="12px" viewBox="0 0 10 10" focusable="false"><polygon class="a-s-fa-Ha-pa" fill="#969696" points="10,1.01 8.99,0 5,3.99 1.01,0 0,1.01 3.99,5

我有以下html:

<a class="delete show-modal" href="#;">
    <svg x="0px" y="0px" width="12px" height="12px" viewBox="0 0 10 10" focusable="false"><polygon class="a-s-fa-Ha-pa" fill="#969696" points="10,1.01 8.99,0 5,3.99 1.01,0 0,1.01 3.99,5 0,8.99 1.01,10 5,6.01 8.99,10 10,8.99 6.01,5 "></polygon></svg>
</a>

换句话说,我认为弹出窗口没有被触发,因为单击的元素显示为
svg
,而不是
a
您的svg,它已经是您链接的一部分。也许您的问题是“如何在不使用javascript的情况下显示弹出窗口?” 在这种情况下,您可以使用css属性:target

不带JavaScript的弹出/模式窗口
我来了
谢谢你把我从按钮上弹出,但是现在我已经完成了,所以你可以关闭这个窗口。
身体{
字体系列:Arial,无衬线;
背景:url(http://www.shukatsu-note.com/wp-content/uploads/2014/12/computer-564136_1280.jpg)不重复;
背景尺寸:封面;
高度:100vh;
}
h1{
文本对齐:居中;
字体系列:Tahoma,Arial,无衬线;
颜色:#06D85F;
利润率:80px0;
}
.盒子{
宽度:40%;
保证金:0自动;
背景:rgba(255255,0.2);
填充:35px;
边框:2倍实心#fff;
边界半径:20px/50px;
背景剪辑:填充框;
文本对齐:居中;
}
.按钮{
字号:1em;
填充:10px;
颜色:#fff;
边框:2个实心#06D85F;
边界半径:20px/50px;
文字装饰:无;
光标:指针;
过渡:所有0.3秒放松;
}
.按钮:悬停{
背景#06D85F;
}
.覆盖{
位置:固定;
排名:0;
底部:0;
左:0;
右:0;
背景:rgba(0,0,0,0.7);
过渡:不透明度500ms;
可见性:隐藏;
不透明度:0;
}
.覆盖:目标{
能见度:可见;
不透明度:1;
}
.弹出窗口{
利润率:70像素自动;
填充:20px;
背景:#fff;
边界半径:5px;
宽度:30%;
位置:相对位置;
过渡:所有5s易于输入输出;
}
.弹出窗口h2{
边际上限:0;
颜色:#333;
字体系列:Tahoma,Arial,无衬线;
}
.弹出.关闭{
位置:绝对位置;
顶部:20px;
右:30px;
过渡:所有200ms;
字体大小:30px;
字体大小:粗体;
文字装饰:无;
颜色:#333;
}
.弹出.关闭:悬停{
颜色:#06D85F;
}
.popup.content{
最高高度:30%;
溢出:自动;
}
@媒体屏幕和屏幕(最大宽度:700px){
.盒子{
宽度:70%;
}
.弹出窗口{
宽度:70%;
}
}

您的问题是svg是单击的目标,它没有您要查找的类。要解决此问题,您可以将
show modal
类添加到锚点中的所有元素,或者只需添加此CSS:

.show-modal *{
  pointer-events: none;
}
pointer events
CSS属性设置特定图形元素在什么情况下(如果有)会成为鼠标事件的目标。这里有更多的信息

请参阅此代码段:

$(文档).on('click',函数(e){
变量clickedElement=$(即目标);
$this=单击元素;
if($this.hasClass('show-modal')){
警报(“它被点击了”);
}
});
。显示模式*{
指针事件:无;
}


错误不在此代码中,而是在您提出的问题中。您的SVG是链接的一部分,并且将触发附加到链接的事件(给定以下代码)。如果你问如何编写弹出窗口,那是另一个问题。@Ted谢谢,你说得对。我更新了任务的细节。这与
e.target
是什么有关。谢谢,这是一个很好的答案。
指针事件的作用是什么?我以前从未见过那种东西。我会查一下,但如果你能在你的答案中加上一两行关于that@David542它本质上告诉浏览器忽略鼠标——就好像元素根本不存在一样。--啊,我看到你在一个描述和链接中添加了。优秀:)
<h1>Popup/Modal Windows without JavaScript</h1>
<div class="box">
    <a class="button" href="#popup1">Let me Pop up</a>
</div>

<div id="popup1" class="overlay">
    <div class="popup">
        <h2>Here i am</h2>
        <a class="close" href="#">&times;</a>
        <div class="content">
            Thank to pop me out of that button, but now i'm done so you can close this window.
        </div>
    </div>
</div>

body {
  font-family: Arial, sans-serif;
  background: url(http://www.shukatsu-note.com/wp-content/uploads/2014/12/computer-564136_1280.jpg) no-repeat;
  background-size: cover;
  height: 100vh;
}

h1 {
  text-align: center;
  font-family: Tahoma, Arial, sans-serif;
  color: #06D85F;
  margin: 80px 0;
}

.box {
  width: 40%;
  margin: 0 auto;
  background: rgba(255,255,255,0.2);
  padding: 35px;
  border: 2px solid #fff;
  border-radius: 20px/50px;
  background-clip: padding-box;
  text-align: center;
}

.button {
  font-size: 1em;
  padding: 10px;
  color: #fff;
  border: 2px solid #06D85F;
  border-radius: 20px/50px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease-out;
}
.button:hover {
  background: #06D85F;
}

.overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: hidden;
  opacity: 0;
}
.overlay:target {
  visibility: visible;
  opacity: 1;
}

.popup {
  margin: 70px auto;
  padding: 20px;
  background: #fff;
  border-radius: 5px;
  width: 30%;
  position: relative;
  transition: all 5s ease-in-out;
}

.popup h2 {
  margin-top: 0;
  color: #333;
  font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
  position: absolute;
  top: 20px;
  right: 30px;
  transition: all 200ms;
  font-size: 30px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
}
.popup .close:hover {
  color: #06D85F;
}
.popup .content {
  max-height: 30%;
  overflow: auto;
}

@media screen and (max-width: 700px){
  .box{
    width: 70%;
  }
  .popup{
    width: 70%;
  }
}
.show-modal *{
  pointer-events: none;
}