为什么下面的JavaScript语句不能对Text文本区动态赋值?
在页面显示的时候,会显示一个文本框,内容是aaaaa;我想点击“执行”按钮时,让它显示bbbbb。可是当点击“执行”按钮时却提示:“Microsoft JScript 运行时错误: 'txtId ' 未定义”,怎么回事?怎么办呢?
<input type= "text " name= "txtName " id= "txtId " value= "aaaaa " />
<script type= "text/javascript " language= "javascript " >
function SetText()
{
txtId.value= "bbbbb ";
}
</script>
<input type= "button " id= "myBtn " value= "执行 " onclick= "SetText() " />
------解决方案--------------------function SetText()
{
document.getElementById( "txtId ").value= "bbbbb ";
}
------解决方案--------------------function SetText()
{
document.getElementById( "txtId ").value= "bbbbb ";
}
----------------------------------------------------
up
------解决方案--------------------html的input也是不能直接用id来赋值的,都要得document.get...().value或document.all( " ").value
------解决方案--------------------function SetText()
{
document.getElementById( "txtId ").value= "bbbbb ";
}
或者
function SetText()
{
document.all( "txtId ").value= "bbbbb ";
}
------解决方案--------------------document.all( "txtId ").value= "bbbbb ";
------解决方案--------------------楼上的说的都对
function SetText()
{
document.getElementById( "txtId ").value= "bbbbb ";
}
------解决方案--------------------document.getElementsID()
------解决方案--------------------function SetText()
{
document.getElementById( "txtId ").InnerText= "bbbbb ";
}
或
function SetText()
{
document.getElementById( "txtId ").Innethtml= "bbbbb ";
}
------解决方案--------------------同意一楼及和一楼答案一致的所有的答案