HTML文件:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TransferReg.aspx.cs" Inherits="W90.Web.Member.TransferReg" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="js/PCA.js" type="text/javascript"></script>
</head>
<body>
<TABLE>
<tr>
<td valign="top">
地址:</td>
<td>
<!--省市区-->
省:<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
市:<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
区:<asp:DropDownList id="DropDownList3" runat="server"></asp:DropDownList>
</td>
</tr>
</TABLE><body>
js文件:
/*
xml+ajax无刷新联动省市区功能
create by tongwh
2008.12.18
*/
function CityResult(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_provice.ClientID%>").value = parent_id.text;
//alert(parent_id.text);
//alert(document.getElementById("lbl_provice").value);
document.getElementById("<%=this.lbl_provice_id.ClientID%>").value = parent_id.value;
WebForm1.BindCity(parent_id.value,objDropDownList,get_City_Result_CallBack);
}
function get_City_Result_CallBack(response)
{
if (response.value != null)
{
var ds = response.value;
var first_city;
var first_city_id;
//绑定城市
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
document.getElementById("<%=this.DDLCity.ClientID%>").length = 0;
for(var i=0; i<ds.Tables[0].Rows.length; i++){
var name=ds.Tables[0].Rows[i].Text;
var id=ds.Tables[0].Rows[i].Value;
if(i==0){first_city = name;first_city_id = id};
document.getElementById("<%=this.DDLCity.ClientID%>").options.add(new Option(name,id));
}
//每次省选择以后,赋省下第一个城市值
document.getElementById("<%=this.lbl_city.ClientID%>").innerText = first_city;
//绑定地区
if(first_city_id&&typeof(first_city_id)!='undefined')
WebForm1.BindArea(first_city_id, '<%=this.DDLArea.ClientID%>"', get_Area_Result_CallBack);
else{
document.getElementById("<%=this.DDLArea.ClientID%>").length = 0;
}
}
}
}function AreaResult(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_city.ClientID%>").innerText = parent_id.text;
WebForm1.BindArea(parent_id.value,objDropDownList,get_Area_Result_CallBack);
}
function get_Area_Result_CallBack(response)
{
if (response.value != null){
var ds = response.value;
var first_area;
var first_area_id;
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
document.getElementById("<%=this.DDLArea.ClientID%>").length = 0;
for(var i=0; i<ds.Tables[0].Rows.length; i++){
var name=ds.Tables[0].Rows[i].Text;
var id=ds.Tables[0].Rows[i].Value;
if(i==0){first_area = name;first_area_id = id};
document.all("<%=this.DDLArea.ClientID%>").options.add(new Option(name,id));
}
//每次城市后 赋第一个地区值
document.getElementById("<%=this.lbl_area.ClientID%>").innerText = first_area;
}
}
}
function AreaResultV(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_area.ClientID%>").innerText = parent_id.text;
//dropdownlist_ajaxpro_Default.BindArea(parent_id.value,objDropDownList,get_Area_Result_CallBack);
}
问题:
如果把以上的JS代码直接复制到ASPX页面里则不会出错,功能可以正常。但是如果把以上的JS保存到JS文件,然后调用则会出现 :[color=#000000]调用外部JS文件后出现JavaScript中getElementById()为空或不是对象 的问题。请MSDN上的朋友指点指点。谢谢! [/color]
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="js/PCA.js" type="text/javascript"></script>
</head>
<body>
<TABLE>
<tr>
<td valign="top">
地址:</td>
<td>
<!--省市区-->
省:<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
市:<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
区:<asp:DropDownList id="DropDownList3" runat="server"></asp:DropDownList>
</td>
</tr>
</TABLE><body>
js文件:
/*
xml+ajax无刷新联动省市区功能
create by tongwh
2008.12.18
*/
function CityResult(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_provice.ClientID%>").value = parent_id.text;
//alert(parent_id.text);
//alert(document.getElementById("lbl_provice").value);
document.getElementById("<%=this.lbl_provice_id.ClientID%>").value = parent_id.value;
WebForm1.BindCity(parent_id.value,objDropDownList,get_City_Result_CallBack);
}
function get_City_Result_CallBack(response)
{
if (response.value != null)
{
var ds = response.value;
var first_city;
var first_city_id;
//绑定城市
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
document.getElementById("<%=this.DDLCity.ClientID%>").length = 0;
for(var i=0; i<ds.Tables[0].Rows.length; i++){
var name=ds.Tables[0].Rows[i].Text;
var id=ds.Tables[0].Rows[i].Value;
if(i==0){first_city = name;first_city_id = id};
document.getElementById("<%=this.DDLCity.ClientID%>").options.add(new Option(name,id));
}
//每次省选择以后,赋省下第一个城市值
document.getElementById("<%=this.lbl_city.ClientID%>").innerText = first_city;
//绑定地区
if(first_city_id&&typeof(first_city_id)!='undefined')
WebForm1.BindArea(first_city_id, '<%=this.DDLArea.ClientID%>"', get_Area_Result_CallBack);
else{
document.getElementById("<%=this.DDLArea.ClientID%>").length = 0;
}
}
}
}function AreaResult(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_city.ClientID%>").innerText = parent_id.text;
WebForm1.BindArea(parent_id.value,objDropDownList,get_Area_Result_CallBack);
}
function get_Area_Result_CallBack(response)
{
if (response.value != null){
var ds = response.value;
var first_area;
var first_area_id;
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
document.getElementById("<%=this.DDLArea.ClientID%>").length = 0;
for(var i=0; i<ds.Tables[0].Rows.length; i++){
var name=ds.Tables[0].Rows[i].Text;
var id=ds.Tables[0].Rows[i].Value;
if(i==0){first_area = name;first_area_id = id};
document.all("<%=this.DDLArea.ClientID%>").options.add(new Option(name,id));
}
//每次城市后 赋第一个地区值
document.getElementById("<%=this.lbl_area.ClientID%>").innerText = first_area;
}
}
}
function AreaResultV(parent_id,objDropDownList){
document.getElementById("<%=this.lbl_area.ClientID%>").innerText = parent_id.text;
//dropdownlist_ajaxpro_Default.BindArea(parent_id.value,objDropDownList,get_Area_Result_CallBack);
}
问题:
如果把以上的JS代码直接复制到ASPX页面里则不会出错,功能可以正常。但是如果把以上的JS保存到JS文件,然后调用则会出现 :[color=#000000]调用外部JS文件后出现JavaScript中getElementById()为空或不是对象 的问题。请MSDN上的朋友指点指点。谢谢! [/color]
解决方案 »
- localhost怎么也连接不上,127.0.0.1就行,怎么办?
- 如何用程序实现把网页中的图片自动保存到本地
- 关于多语言网站的设计 欢迎大家前来拍砖灌水 - -
- 帮忙解决乱码的问题
- 有没有人知道c#中webform里的TabStrip控件的用法,我想在每个tab页上添加控件怎么弄
- 通过asp 下载文件的管理
- 建议开sharepoint版块,大家的意见呢?
- 怎样让一个DATAGRID生成的页面中的数据由一个<table>按条件分成若干个<table>中?
- 批量删除的问题(为学习已倾家荡产~~)
- 团队合作开发时如何把".dll"放在同一个bin下面,高手请进。
- UrlRewrite太鸡肋!(感想)
- 大家给推荐一本asp.net入门的书
显然你写到js文件里面,是不行的。
不知道我这么说你明白没有?