About NAME Attribute | name Property

iflyer 2002-10-24 12:00:08
在MSDN上说:

The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.

Examples

The following example shows how to set the NAME attribute on a dynamically created A element.

var oAnchor = document.createElement("<A NAME='AnchorName'></A>");

描述和例子好像矛盾,run time到底是什么概念?
...全文
35 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
希默软件 2002-10-25
  • 打赏
  • 举报
回复
但是你使用qaz能调用它吗?
iflyer 2002-10-25
  • 打赏
  • 举报
回复
但是,下面的网页代码可以运行。为什么?

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<SELECT ID="oSelect">
<OPTION VALUE="1">One</OPTION>
</SELECT>

<SCRIPT>
var oOption = document.createElement("OPTION");
oSelect.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
oOption.name = "qaz";
alert(document.body.outerHTML);
</SCRIPT>
</body>
</html>
希默软件 2002-10-25
  • 打赏
  • 举报
回复
这里run time是即时生成的意思,这里这个<A NAME='AnchorName'></A>并不是页面中本来存在的,是使用createElement后才生成的,它是动态生成的元素

The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.

这句话是说你不能在使用createElement创建元素后再给它增加name属性,必须在使用createElement创建改元素的时候就加上,例如它的例子document.createElement("<A NAME='AnchorName'></A>");
wangxj0600 2002-10-24
  • 打赏
  • 举报
回复
意思是你不能给动态生成的元素设置name,只能在创建的时候设置name。
iflyer 2002-10-24
  • 打赏
  • 举报
回复
wangxj0600(wamgxj0600):什么叫动态生成的元素,能否举例说明一下,谢谢!

87,996

社区成员

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

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