【发布时间】:2020-06-11 18:43:40
【问题描述】:
我有以下代码。它由一条线组成,其末端附有一个标记。我为线条和标记写了一个点击事件。但是当我单击标记元素时,单击事件不起作用,并且光标类型等 CSS 属性也没有设置。如何为标记元素编写点击事件并应用 css 属性?
$("#line12").on("click",function() {
alert("Hai You clicked the line")
})
$("#arrow").on("click",function() {
alert("Hai You clicked the line")
})
#line12
{
cursor:pointer;
}
#arrow
{
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg width="600px" height="200px">
<defs>
<marker id="arrow" markerWidth="10" markerHeight="10" refx="0" refy="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#000" />
</marker>
</defs>
<line x1="50" y1="50" x2="250" y2="150" stroke="#000" id="line12" stroke-width="5" marker-end="url(#arrow)" />
</svg>
【问题讨论】: