document.getElementsByName()返回的是一个集合(collection)
p.value,这里属性名应该小写<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form id=frm name=frm >
<P><INPUT id=button1 type=button onclick="javascript:test();" value=Button name=button1><INPUT id=text1 name=text1 value=""></P>
</form>
<script language=javascript>
function test(){
var Ctrl="text1"
//var p=document.frm.elements(Ctrl)
var p=document.getElementsByName(Ctrl)
p[0].value="OK";
}
</script>
</BODY>
</HTML>
p.value,这里属性名应该小写<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form id=frm name=frm >
<P><INPUT id=button1 type=button onclick="javascript:test();" value=Button name=button1><INPUT id=text1 name=text1 value=""></P>
</form>
<script language=javascript>
function test(){
var Ctrl="text1"
//var p=document.frm.elements(Ctrl)
var p=document.getElementsByName(Ctrl)
p[0].value="OK";
}
</script>
</BODY>
</HTML>
var p=frm.elements("text1")或者var p=frm.text1;效率高一些