//先给年下拉框赋内容 var y =new Date().getFullYear(); for (var i = (y-30); i < (y+30); i++) //以今年为准,前30年,后30年 document.form1.YYYY.options.add(new Option(""+ i +" 年", i));
//赋月份的下拉框 for (var i =1; i <13; i++) document.form1.MM.options.add(new Option(""+ i +" 月", i));
document.form1.YYYY.value = y; document.form1.MM.value =new Date().getMonth() +1; var n = MonHead[new Date().getMonth()]; if (new Date().getMonth() ==1&& IsPinYear(YYYYvalue)) n++; writeDay(n); //赋日期下拉框 document.form1.DD.value =new Date().getDate(); } if(document.attachEvent) window.attachEvent("onload", YYYYMMDDstart); else window.addEventListener('load', YYYYMMDDstart, false); function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年) { var MMvalue = document.form1.MM.options[document.form1.MM.selectedIndex].value; if (MMvalue ==""){ var e = document.form1.DD; optionsClear(e); return;} var n = MonHead[MMvalue -1]; if (MMvalue ==2&& IsPinYear(str)) n++; writeDay(n) } function MMDD(str) //月发生变化时日期联动 { var YYYYvalue = document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value; if (YYYYvalue ==""){ var e = document.form1.DD; optionsClear(e); return;} var n = MonHead[str -1]; if (str ==2&& IsPinYear(YYYYvalue)) n++; writeDay(n) } function writeDay(n) //据条件写日期的下拉框 { var e = document.form1.DD; optionsClear(e); for (var i=1; i<(n+1); i++) e.options.add(new Option(""+ i +" 日", i)); } function IsPinYear(year)//判断是否闰平年 { return(0== year%4&& (year%100!=0|| year%400==0)); } function optionsClear(e) { e.options.length =1; } //--> </script> </body> </HTML>
if(result !="") { document.all("DropDownList2").length=0; var piArray = result.split(","); for(var i=0;i<piArray.length;i++) { var ary1 = piArray[i].toString().split("|"); document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString())); } } else { alert(result); } } //以XML求取DropDownList3的数据 function XmlPost3(obj) { var svalue = obj.value; var webFileUrl ="?cityid="+ svalue; var result =""; var xmlHttp =new ActiveXObject("MSXML2.XMLHTTP"); xmlHttp.open("POST", webFileUrl, false); xmlHttp.send(""); result = xmlHttp.responseText;
if(result !="") { document.all("DropDownList3").length=0; var piArray = result.split(","); for(var i=0;i<piArray.length;i++) { var ary1 = piArray[i].toString().split("|"); document.all("DropDownList3").options.add(new Option(ary1[1].toString(),ary1[0].toString())); } } else { alert(result); } } function getData() { var province=document.getElementById("DropDownList1"); var pindex = province.selectedIndex; var pValue = province.options[pindex].value; var pText = province.options[pindex].text;
var city=document.getElementById("DropDownList2"); var cindex = city.selectedIndex; var cValue = city.options[cindex].value; var cText = city.options[cindex].text;
var area=document.getElementById("DropDownList3"); var aindex = area.selectedIndex; var aValue = area.options[aindex].value; var aText = area.options[aindex].text;
down2_bind#region down2_bind privatevoid down2_bind(string id) { string mystr =""; string sql ="select cityID,city from city where father = '"+ id +"'"; DataSet ds = GetDataSet(sql);
down3_bind#region down3_bind privatevoid down3_bind(string id) { string mystr =""; string sql ="select areaID,area from area where father = '"+ id +"'"; DataSet ds = GetDataSet(sql);
Web Form Designer generated code#region Web Form Designer generated code overrideprotectedvoid OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/**////<summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///</summary> privatevoid InitializeComponent() { this.Button1.ServerClick +=new System.EventHandler(this.Button1_ServerClick); this.Load +=new System.EventHandler(this.Page_Load);
<HTML> <HEAD> <title>jsWebServices</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script language="javascript"> <!-- var str_province; var str_city; var str_area;
function window_onload() { service.useService("/Service1.asmx?WSDL","myselect"); str_province=service.myselect.callService(province_Result,"getProvince"); }
function province_Result(result) { if(!result.error) { document.all("select_province").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("select_province").options.add(new Option(ary1[1].toString(),ary1[0].toString())); } } }
function province_onchange() { var province=document.getElementById("select_province"); var pindex = province.selectedIndex; var pValue = province.options[pindex].value; var pText = province.options[pindex].text; str_city=service.myselect.callService(city_Result,"getCity",pValue); }
function city_onchange() { var city=document.getElementById("select_city"); var cindex = city.selectedIndex; var cValue = city.options[cindex].value; var cText = city.options[cindex].text; str_area=service.myselect.callService(area_Result,"getArea",cValue); }
function city_Result(result) { if(!result.error) { document.all("select_city").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("select_city").options.add(new Option(ary1[1].toString(),ary1[0].toString())); } } }
Required. The
id
of the element to which the
WebService
behavior is attached.
sWebServiceURL
Required. String specifying the URL of the Web Service, using one of the following path types. See the examples section, where several variations of this parameter are shown.
Web Service file name
A Web service file, which has an .asmx file extension. This short form of the URL is sufficient, provided that the Web service is located in the same folder as the Web page using the WebService behavior. In this case, the ?WSDL query string is assumed by the behavior.
WSDL file name
A Web Services Description Language (WSDL) file name. The WSDL file must have a .wsdl file extension.
Full file path
Full path to a WebService (.asmx) or WSDL (.wsdl) file. A file path to a Web Service must include the ?WSDL query string. Either a local file path or a URL can be specified.
Relative path
A relative path to a WebService (.asmx) or WSDL (.wsdl) file. A file path to a Web Service must include the ?WSDL query string.
sFriendlyName
Required. String representing a friendly name for the Web Service URL.
//Required by the Web Services Designer private IContainer components =null;
/**////<summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///</summary> privatevoid InitializeComponent() { }
/**////<summary> /// Clean up any resources being used. ///</summary> protectedoverridevoid Dispose( bool disposing ) { if(disposing && components !=null) { components.Dispose(); } base.Dispose(disposing); }
getCity#region getCity [WebMethod(true)] publicstring getCity(string provinceid) { string str="select * from city where father = '"+provinceid+"'"; SqlCommand cmd=new SqlCommand(str,conn);
if(event.keyCode==13) { var select_obj = document.getElementById("myselect"); var text_value = document.getElementById("test").value;
if (select_obj.length) { for (var i=0;i<select_obj.length;i++) { // 如果已经存在,不添加,直接退出 if (select_obj.options[i].text==text_value) alert("选项已存在,请重新输入"); } } var the_option=new Option(text_value,text_value);
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient;
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码 overrideprotectedvoid OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); }
Feedback
永远支持楼主,多多发表一些技术性文章!!!!!!!!!!
回复
但是在静态的可以,是不是还要再引用什么,还是加什么语句呢??
总是提示错误:缺少")",而且下面已经定义的变量,它也没说定义!!!!!!
用静态的直接就可以了,我测试了很久都不行,是不是在ASP.NET不行呢?
望楼主看到消息,能给个回复???????? 回复
您能不能也做个ASP.NET的,把它里面代码一些该改的给改一下,那后再上传一下,好吗? 回复
什么原因会导致一个行,一个不行呢?
希望楼主能给我解释一下? 回复
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
<httpHandlers> 回复
分析器错误信息: 行“98”上的“httpHandlers”开始标记与文件“file:///c:/inetpub/wwwroot/城市下拉/web.config”中的结束标记“system.web”不匹配。 行 99,位置 4。
源错误:
行 97: />
行 98: <httpHandlers>
行 99: </system.web>
行 100:
行 101:</configuration>
还是要加在什么地方呢??????????
回复
后缀让它是.aspx,不是HTML!而且在.NET环境中可以运行出效果来呢?
一直想弄清楚,浪费了快一天时间呢?
有时间的话,能不能做个上传上来呢? 回复