当前位置: 代码迷 >> J# >> 初学者提问,通过js改变上面的属性值
  详细解决方案

初学者提问,通过js改变上面的属性值

热度:993   发布时间:2013-02-25 00:00:00.0
菜鸟提问,通过js改变下面的属性值
<svg width="200" height="250">  
  <rect id="x" x="10" y="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/>  
  <rect x="60" y="10" rx="10" ry="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/>  
</svg> 
比如这样一段html,我如何能通过js,去改变这个id为x,的rect的长,宽,高什么的啊
------最佳解决方案--------------------------------------------------------
document.getElementsByTagName("svg")[0].children[0].setAttribute("id", "xxx")
w = document.getElementsByTagName("svg")[0].children[0].getAttribute("width")
------其他解决方案--------------------------------------------------------
引用:
document.getElementsByTagName("svg")[0].children[0].setAttribute("id", "xxx")
w = document.getElementsByTagName("svg")[0].children[0].getAttribute("width")


同意
------其他解决方案--------------------------------------------------------
document.getElementsByTagName("svg")[0].children[0].setAttribute("id", "xxx")
w = document.getElementsByTagName("svg")[0].children[0].getAttribute("width")
------其他解决方案--------------------------------------------------------
引用:
document.getElementsByTagName("svg")[0].children[0].setAttribute("id", "xxx")
w = document.getElementsByTagName("svg")[0].children[0].getAttribute("width")
这个就可以了
------其他解决方案--------------------------------------------------------
新论坛的样子,不错
------其他解决方案--------------------------------------------------------
该回复于2012-11-07 17:20:20被管理员删除
  相关解决方案