日期:2014-05-19  浏览次数:20771 次

调用js时,提示缺少对象
在看一个网页代码时,发现下面一处代码:
<!-- 搜索、人数 -->
<div id="soren">
<div class="search"> 
<form action="cp.php" method="get">
<input type="hidden" name="ac" value="friend">
<input type="hidden" name="op" value="search">
<input type="hidden" name="all" value="yes">
<input type="hidden" name="searchsubmit" value="找人">
<input type="hidden" name="searchmode" value="1">
<b>快速搜索</b>&nbsp;&nbsp;我要找&nbsp;<select name="sex" size="1"><option value="2"> 美女</option><option value="1">帅哥</option></select>&nbsp;&nbsp;
年龄<input type="text" name="startage" value="18" size="2" class="t_input" />&nbsp;&nbsp;到&nbsp;&nbsp;
<input type="text" name="endage" value="32" size="2" class="t_input" />&nbsp;&nbsp;
地区 &nbsp;&nbsp;<span id="residecitybox1"></span>
<script type="text/javascript">showprovince('resideprovince', 'residecity', '', 'residecitybox1');showcity('residecity', '', 'resideprovince', 'residecitybox1');</script>&nbsp;&nbsp;
<input type="checkbox" name="avatar" value="1" class="in">有照片&nbsp;
<input type="submit" class="submit" value="开始搜索">
</form>
</div> 
</div>
<!-- 搜索、人数end -->

  其使用的JS文件,也导入了,JS内容大致如下 :

function showprovince(provinceid, cityid, province, boxid) {
var provinces = new Array(
"北京", "上海", "重庆", "安徽", "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北", "黑龙江", "河南",
"香港", "湖北", "湖南", "江苏", "江西", "吉林", "辽宁", "澳门", "内蒙古", "宁夏", "青海", "山东",
"山西", "陕西", "四川", "台湾", "天津", "新疆", "西藏", "云南", "浙江"
);
/*var provinces = new Array(
"北京", "上海", "重庆", "安徽", "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北", "黑龙江", "河南",
"香港", "湖北", "湖南", "江苏", "江西", "吉林", "辽宁", "澳门", "内蒙古", "宁夏", "青海", "山东",
"山西", "陕西", "四川", "台湾", "天津", "新疆", "西藏", "云南", "浙江", "海外"
);*/

var selObj = document.createElement("select");
selObj.name = provinceid;
selObj.id = provinceid;
selObj.onchange = function() {
setcity(provinceid, cityid);
};
$(boxid).appendChild(selObj);

selObj.options[0] = new Option("选择省份", "");
var j = 0;
for(var i = 0; i < provinces.length; i++) {
j = i + 1;
selObj.options[j] = new Option(provinces[i], provinces[i]);
}

initprovcity(provinceid, province);

}

function showcity(cityid, city, provinceid, boxid) {
if(isUndefined(provinceid)) provinceid = '';

var selObj = document.createElement("select");
s