大家好,
我有一个form如下:
<form name="searchForm" action="userservcenter.cgi?" method="post"
enctype=""><input type="hidden" name="program" value="search"><input
type="hidden" name="tab_id" value="Employees"><input
type="hidden" name="startFrom" value="0"><input type="hidden"
name="getPrevRecords" value="false"><input type="hidden"
name="noOfFields" value="1"><input type="hidden"
name="displayFormat" value="2"><input type="hidden"
name="advSearch" value="false"><input type="hidden"
name="searchStringMinimumLength" value="1"><input type="hidden"
name="searchSameAttrAsOr" value="false">
<table width="100%" border="0" bgcolor="#333399" cellpadding="6"
cellspacing="0">
<script language="JavaScript" src="../../../lang/shared/gmin_search.js"></script>
<tr align="right">
<td align="right" valign="middle" nowrap><font
face="Ariel, Helvetica, sans-serif" size="2" color="#FFFFFF">Search</font>
? <select onchange="searchCriteria(this)" name="STy1" id="STy1"
size="1">
<option value="sn" selected="true">Family/Last Name</option>
<option value="cn">Full Name</option>
<option value="gmuniqueidentifier" selected="true">GMIN</option>
</select><font color="#000000" face="Arial, Helvetica, sans-serif" size="2"><select
name="SLk1" id="SLk1" size="1">
<option value="OBW">That Begins With</option>
<option value="OOS">That Contains</option>
<option value="OEM" selected="true">That Equals</option>
</select></font><font color="#000000" face="Arial, Helvetica, sans-serif" size="2"><input
type="text" name="SSt1" id="SSt1" size="19" maxlength="100"
onKeyDown="javascript:checkSearchKey(event,this)" value="111"></font><input
type="hidden" name="showAllResults" value="true"><input
type="hidden" name="noOfRecords" id="noOfRecords" size="2"
maxlength="100" value="20"> ?? <a onmouseout="self.status=''"
onmouseover="self.status='Start search.'; return true"
href="javascript:validateSearchAndSubmit('search')"><img
src="../../../lang/en-us/gmposmgt//SEARCHgo.gif" border="0"></a>
??</td>
</tr>
</table>
</form>
我想在gmin_search.js里写一个function 用来在页面load时判断下拉框STy1是否为GMIN状态。于是我定义了var sel = document.getElementById('SLk1');但是确为null。为什么呢?
我自己也用下面代码去调试了,但是遍历所有element都找不到SLk1,这又是为什么呢?谢谢!
for(i=0;i<document.forms.length;i++){
for(j=0;j<document.forms[i].elements.length;j++){
var name = document.forms[i].elements[j].name;
var value = document.forms[i].elements[j].value;
alert(i + ', ' + j)
alert(name);
alert(value);
}
}
------解决方案--------------------
<script language="JavaScript" src="../../../lang/shared/gmin_search.js"></script>
放在页面的最下边。
------解决方案--------------------
首先检查 js 路径和编码是否正确
把要执行的js 放 window.onload 中