日期:2014-05-16  浏览次数:20360 次

[高分求救]setAttribute('innerText','5555');的所有替代方法

document.getElementById( 'textTechUserName ').setAttribute( 'innerText ', '5555 ');
最好是类似
label.appendChild(document.createTextNode(textToAdd));
的替代方法。
比如说我还可以
document.getElementById( 'textTechUserName ').innerText   =   '5555 ';
我不知道有没有类似.appendChild的方法可以用。


------解决方案--------------------
// 这句的作用就是设置 innerText 属性为 'innerText '
document.getElementById( 'textTechUserName ').setAttribute( 'innerText ', '5555 ');

// 替代语句 LZ 自己已经写了
document.getElementById( 'textTechUserName ').innerText = '5555 ';

// 这句的作用是添加子元素,只有那些配对标记可以使用,例如: <LABEL> </LABEL>
label.appendChild(document.createTextNode(textToAdd));

input 是自封闭标记,不是配对标记,因此无法使用 DOM 操作为其添加文本节点,
只能通过属性进行修改!
------解决方案--------------------
innerHTML
------解决方案--------------------
LZ 的问题似乎出在,将 DOM 操作与属性设置两个概念混淆了!

LZ 居然希望通过 DOM 操作来完成属性设置?!
------解决方案--------------------
俺是根据 LZ 的叙述和代码推测的,

LZ 到底要干嘛?!最好能明示
------解决方案--------------------
document.getElementById( 'textTechUserName ').innerText += '5555 ';//就是累加了
另外觉得appendChild应该也可以用,创建个textNode然后append上就行(这个没有试).
------解决方案--------------------
<body>
<div id=d> </div>
<script>
att = document.createAttribute( "innerText ")
att.value = "new attr "

document.getElementById( "d ").attributes.setNamedItem(att)
alert(document.getElementById( "d ").outerHTML)
</script>
------解决方案--------------------
lable不能给form传数据
要用hidden
------解决方案--------------------
哈,老大又出来忽悠晚辈,

一句搞定的属性设置被老大弄得龙飞凤舞的,哈

开个玩笑,老大莫怪!
------解决方案--------------------
如 mingxuan3000(铭轩) 所言,要用 hidden !

<input type= "hidden " id= "hidMyValue " runat= "server " />

客户端脚本写入:
document.getElementById( 'hidMyValue ').value = '5555 ';

Server 端读取(C#):
string s = hidMyValue.Value;
------解决方案--------------------
LZ 说“我的属性设置在机顶盒的浏览器上会不起作用的”

——那楼主需要查询 机顶盒浏览器 的相关参考文档,而不是到这里提问!

这属于专业问题,并非常用浏览器范畴!