我试图在绑定到使用 d3@3在NodeJS 中创建的 SVG 元素的操作上启用 javascript 代码。不幸的是, on('click') 没有呈现。
router.get('/test', function(req, res) {
const dom = new JSDOM();
var svg = d3.select(dom.window.document.body)
.append("svg")
.attr("xmlns", "http://www.w3.org/2000/svg")
svg.insert('rect')
.attr("width", 200)
.attr("height", 200)
.on('click', function() { console.log('click')});
svgStr = dom.window.document.body.innerHTML;
res.set('Content-Type', 'image/svg+xml');
res.send(svgStr);
})
输出:
<svg xmlns="http://www.w3.org/2000/svg"><rect width="200" height="200">
</rect></svg>
on('click') 在哪里?
放
`
//...
.attr("height", 200)
.attr("onclick" , "console.log('click')")`
为你点击
并记住不允许从图像到页面的操作
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句