没错,即使多了个空格也不提示错的。把它输出,试一下: <form name="dynamiccombo" method="post" runat="server"> <select name="stage2" size="0" onchange="displaysub()"> <option value="#1" selected>this is a place</option> <option value="#2">this is a place</option> <option value="#3">this is a place</option> <option value="#4">this is a place</option> </select> <input type="button" name="btgo" value="GO!" onclick="gothere()"> </form> <script language="javascript"> function gothere() { var cacheobj=document.dynamiccombo .stage2 ; alert(cacheobj.value); } </script>
<form name="dynamiccombo" method="post" runat="server"> <select name="stage2" size="0" onchange="displaysub()"> <option value="#1" selected>this is a place</option> <option value="#2">this is a place</option> <option value="#3">this is a place</option> <option value="#4">this is a place</option> </select> <input type="button" name="btgo" value="GO!" onclick="gothere()"> </form> <script language="javascript"> function gothere() { var cacheobj = document.dynamiccombo.stage2; alert(cacheobj.value); } function displaysub() { var cacheobj = document.dynamiccombo.stage2; alert(cacheobj.value); } </script>
只是多了一个空格。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>无标题文档</title> </head><body> <form name="dynamiccombo" method="post" runat="server"> <select name="stage2" size="0" onchange="displaysub()"> <option value="#" selected>this is a place</option> <option value="#">this is a place</option> <option value="#">this is a place</option> <option value="#">this is a place</option> </select> <input type="button" name="btgo" value="GO!" onclick="gothere()"> </form> <script language="javascript"> var cacheobj=document.dynamiccombo.stage2 </script>
meizz(梅花雪)查了一下源文件,为何变成这样
<form name="_ctl0" method="post" action="combo box.aspx" id="_ctl0">
<form name="dynamiccombo" method="post" runat="server">
<select name="stage2" size="0" onchange="displaysub()">
<option value="#1" selected>this is a place</option>
<option value="#2">this is a place</option>
<option value="#3">this is a place</option>
<option value="#4">this is a place</option>
</select>
<input type="button" name="btgo" value="GO!" onclick="gothere()">
</form>
<script language="javascript">
function gothere()
{
var cacheobj=document.dynamiccombo .stage2 ;
alert(cacheobj.value);
}
</script>
<select name="stage2" size="0" onchange="displaysub()">
<option value="#1" selected>this is a place</option>
<option value="#2">this is a place</option>
<option value="#3">this is a place</option>
<option value="#4">this is a place</option>
</select>
<input type="button" name="btgo" value="GO!" onclick="gothere()">
</form>
<script language="javascript">
function gothere()
{
var cacheobj = document.dynamiccombo.stage2;
alert(cacheobj.value);
}
function displaysub()
{
var cacheobj = document.dynamiccombo.stage2;
alert(cacheobj.value);
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<form name="dynamiccombo" method="post" runat="server">
<select name="stage2" size="0" onchange="displaysub()">
<option value="#" selected>this is a place</option>
<option value="#">this is a place</option>
<option value="#">this is a place</option>
<option value="#">this is a place</option>
</select>
<input type="button" name="btgo" value="GO!" onclick="gothere()">
</form>
<script language="javascript">
var cacheobj=document.dynamiccombo.stage2
</script>
<script id=clientEventHandlersJS language=javascript>
<!-- // 此处必须加上固定字符。function document_onclick() {}//-->
</script>
可运行后查看源文件却成了<form name="_ctl0" method="post" action="combo box.aspx" id="_ctl0">
可能是因为这个,当然document.dynamiccombo.stage2 会为空对象,可又不知道为什么为变成这样?能帮我解释一下