顺晟科技
2022-09-16 07:22:20
124
请问一下两种创建path和line的方法一样吗,
let line = document.createElement('line')
line.style.x1 = this.x1
line.style.y1 = this.y1
line.style.x2 = this.x2
line.style.y2 = this.y2
line.style.stroke = 'rgb(51, 51, 51)'
line.style.strokeWidth = 3
xxx.appendChild(line)
//这样创建line标签无法显示
xxx.innerHTML = `<path d="M${this.x1},${this.y1}L${this.x2},${this.y2}" stroke="#ff8a27" stroke-width="3" style="marker-end: url(#arrow);"></path>`
//这样创建line标签正常显示
let path = document.createElement('line')
path.setAttribute('d', `M${10},${10}L${100},${100}`)
path.style.stroke = 'red'
path.style.strokeWidth = 2
console.log(line)
xxx.appendChild(path)
//path无法显示
xxx.innerHTML = `<path id="e0" class="line" d="M${this.x1},${this.y1}L${this.x2},${this.y2}" stroke="#ff8a27" stroke-width="3" style="marker-end: url(#arrow);"></path>`
//path能正常显示
请问这是为什么么呢,而且在使用path标签时添加 mark-end:url(#arrow)为什么没有效果呢?
你这个代码写的。line和path都混在一起了,没发现吗
两个innerHTML都写的path,缺少line的方式,这是可以展现的,就不说了
上面的line,x1这些是属性,不是样式,不应该line.style.x1 = this.x1
取设置,要想你下面写path一样去line.setAttribute('x1', this.x1)
下面的是path,createElement创建标签是let path = document.createElement('path')
不是line
29
2022-11
09
2022-11
09
2022-11
19
2022-10
19
2022-10
19
2022-10