在Javascripts D3中附加图像的另一种方法 [英] Another way of appending images in Javascripts D3

查看:89
本文介绍了在Javascripts D3中附加图像的另一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用它来附加图像:

Currently using this to append images :

nodes.append("image")
    .attr("xlink:href", "./randomFile/randomImage")
    .attr("x", -12)
    .attr("y", -12)
    .attr("width", 50)
    .attr("height", 50)
    ;

使用"xlink:href"通知它.现在,除了在Firefox中运行之外,它都很好用.

Notices its using "xlink:href". Now this works great except in Firefox.

我可以通过shift +单击来选择节点.现在在firefox中执行此操作,因为它在html标记中有一个"href",它将在新窗口(如链接)中打开图像.

I have the ability to select nodes by shift + click. Now in firefox when doing this, as it has a 'href' in the html tag, it opens up the image in a new window (like a link).

我在这里有一个小提琴: http://jsfiddle.net/rxzyLsbg/

I have a fiddle here : http://jsfiddle.net/rxzyLsbg/

您会注意到左移图像+单击该图像不会打开新窗口,因为它具有'src'而不是'href'.

Which you notice the image on the left shift + clicking on that one doesn't open a new window as it has a 'src' not a 'href'.

我该如何在D3中执行此操作?

How do i do this in D3 ?

我尝试更改此内容:

.attr("xlink:href", "./randomFile/randomImage")

对此:

.attr("src", "./randomFile/randomImage")

但是根本不起作用.

我想要的是该图像不要成为链接,以便在按住Shift键并单击该图像时不会打开新窗口.

What I want is for the image not to be a link so it doesn't open a new window when shift + clicking on the image.

推荐答案

我可能对这个问题有误解,您可以尝试将其包装在a标记中并传递给target属性

I might be misunderstanding the question, you could try to wrap it in an a tag and pass it the target attribute

nodes.append("image")
    .attr("href", "./randomFile/randomImage")
    .attr('target', '_blank')
    .attr("x", -12)
    .attr("y", -12)
    .attr("width", 50)
    .attr("height", 50)

这将打开单击任何a的内容,并将使用href作为新标签的内容

That will open whatever a is clicked and will use the href as the content for the new tab

这篇关于在Javascripts D3中附加图像的另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆