小问题,如何根据name或id得到其html标记类型?

fanrongboy 2002-12-23 07:56:54
如html中有:<td name="test"></td>,我可以用document.all("test")找到这个对象,但我如何知道这个"test"的html标记类型("td")?有没有系统函数可调用,如果没有,请给出尽量简单的javascript代码.
...全文
37 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanghk 2002-12-24
  • 打赏
  • 举报
回复
document.all("test").tagName
江南昆虫 2002-12-23
  • 打赏
  • 举报
回复
nodeName范围更广一点。
tagName Possible Values

String that specifies the tag name.


nodeName Possible Values

String that specifies one of the following values:
tagName Name of the element, also available through the tagName property.
attrName Name of the attribute, where the node is an Attribute object.
#text Node is a TextNode object.
fanrongboy 2002-12-23
  • 打赏
  • 举报
回复
二者有什么区别?
softrookie 2002-12-23
  • 打赏
  • 举报
回复
document.all("test").tagName
leaxin 2002-12-23
  • 打赏
  • 举报
回复
document.all("test").nodeName

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧