我做了一个二级连动下拉菜单,无刷新的,调用了webservice,
客户端部分代码:
<script language= "javascript " id= "clientEventHandlersJS ">
<!--
var chassname;
var baordname;
function window_onload()
{
service.useService( "/Service1.asmx?WSDL ", "myselect ");
chassname=service.myselect.callService(province_Result, "getProvince ");
}
function province_Result(result)
{
if(!result.error)
{
document.all( "dalanmu ").length=0;
if(result.value.substring(0,1)== ", ")
result.value =result.value.substring(1,result.length);
var piArray = result.value.split( ', ');
for(var i=0;i <piArray.length;i++)
{
var ary1 = piArray[i].toString().split( '| ');
document.all( "dalanmu ").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
}
function province_onchange()
{
var province=document.getElementById( "dalanmu ");
var pindex = province.selectedIndex;
var pValue = province.options[pindex].value;
var pText = province.options[pindex].text;
baordname=service.myselect.callService(city_Result, "getCity ",pValue);
document.getElementById( " <%=TextBox2.ClientID%> ").innerText=pValue;
}
function city_Result(result)
{
if(!result.error)
{
document.all( "xiaolanmu ").length=0;
if(result.value.substring(0,1)== ", ")
result.value =result.value.substring(1,result.length);
var piArray = result.value.split( ", ");
for(var i=0;i <piArray.length;i++)
{
var ary1 = piArray[i].toString().split( "| ");
document.all( "xiaolanmu ").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
}
function city_onchange()
{
var city=document.getElementById( "xiaolanmu ");
var cindex = city.selectedIndex;
var cValue = city.options[cindex].value;
var cText = city.options[cindex].text;
document.getElementById( " <%=TextBox3.ClientID%> ").innerText=cValue;
}
//-->
</script>
</HEAD>
<body onload= "return window_onload() ">
<div id= "service " style= "BEHAVIOR:url(webservice.htc) "> </div>
Service1.asmx.cs代码:
public class Service1 : System.Web.Services.WebService
{
public static string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings[ "constr "];
SqlConnection conn=new SqlConnection(ConnectionString);
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();