求一段js代码 需求是这样的,我现在有两个listbox,1和2 ,我想点一下1中的任何一个item,然后去数据库中去搜col列符合选中的那个值的所有 符合条件记录的某一列(col_ok)列,显示在2中。如果我要点1中的其他值,2中相应的跟着变化。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 想法有了自己应该可以做了啊!先listbox1选好后,listbox1做为参数在数据库中用sql查出啊! 用javascript就得用ajax.很简单的. 我以前是弄winform的,对js不太明白。function SelectOnea() { var lst1=window.document.getElementById("Listbox1"); var lstindex=lst1.selectedIndex; if(lstindex<0) return; var v = lst1.options[lstindex].value; var t = lst1.options[lstindex].text; } 我要是能把v,t的值取出来,估计我就有办法了 2003用__doPostBack2005用document.all.btn.click();--不知道为什么__doPostBack在2005上不能用了。 这位仁兄,我刚才去网上找__doPostBack的相关资料了。可是看的还是一头雾水,能否把关键的几步帮我说下。还有,我上面的代码跟__doPostBack怎么联系起来。。 用js调用 webservice 来实现应该更好些——……var isIE = true; if(window.XMLHttpRequest){ isIE = false;}var xmlHttp;function GetXMLHttpRequest(){ return isIE ? new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();}function calXMLHTTP(){ var szUrl ="http://xxx.com/bbb.asmx?para=nnn"; var oHttp = GetXMLHttpRequest(); oHttp.open("GET", szUrl, false); oHttp.send(); return oHttp.ResponseText;}……或者使用——new ActiveXObject("ADODB.Connection")结合new ActiveXObject("ADODB.RecordSet")使用 做一个隐藏的button<input id=hidbtn runat=server>在后台给listbox1添加属性listbox.item.attribute.add("onclick","__doPostBack('hidbtn','')");写上隐藏button的onclick事件private hidbtn_onclick(...){ 去数据库搜数据赋值给listbox2;}大概是这样,明白吗? 前头的都比较复杂哈。可以在页面中加入一个iframe,高宽设置为0,当listbox1中值变化时,把变化的值提交到iframe中,在后台通过Form方式得到此值。再查询数据库,得到listbox2中值范围,在后台注册一段脚本函数,循环把这些值添加到listbox2中,实际联动并且无刷新。 ls的是asp时代的做法,我也做过,是可以的。 尤其感谢一下SassyBoy(web炼金术师)。 接收数据是根据跟服务端的接口定义来做的,常规的,用js发送就使用前面那段js;如果是c#,可以使用——//***POST ASCIIEncoding encoding=new ASCIIEncoding();string reuqesturl = "http://adasd.com/asd.aspx";string postdata = "xxxxx";byte[] data = encoding.GetBytes(postdata);// Prepare web request...HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);myRequest.Method = "POST";//myRequest.ContentType="application/x-www-form-urlencoded";myRequest.ContentLength = data.Length;Stream newStream = myRequest.GetRequestStream();// Send the data.newStream.Write(data, 0, data.Length);newStream.Close();// Get responseHttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();StreamReader reader = new StreamReader(myResponse.GetResponseStream(),Encoding.Default);string content = reader.ReadToEnd();Console.WriteLine("Get response from server:"+content);myResponse.Close();...//***GET// web requestHttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);myRequest.Credentials = CredentialCache.DefaultCredentials;//myRequest.Method = "GET";//myRequest.ContentType="application/x-www-form-urlencoded";// Get responseHttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();string flag = new StreamReader(response.GetResponseStream()).ReadToEnd();HttpStatusCode code = response.StatusCode;string logtxt = "response status="+code.ToString()+" flag="+flag;Console.WriteLine(logtxt);... winform定时刷新数据 各位大大 这种现象是个神马情况??第一次发帖!帮忙解决一下! 求.net相关技术的学学步骤(Socket,Silverlight,wcf,wpf,mvc等) CheckBoxList 样式 jQuery Alert Dialogs 提示框是怎么用的??? 简单的字符比较大小 SQL语句 高手进来帮帮忙啊!!!在线等 关于颜色选择控件问题 IE6版本以下如何保证通过showModalDialog弹出页面并操作后传回值 关于uploadify多图上传的问题 面弹出新的页面而没有在框架中显示?target='框架的ID' asp.net1.1 datagrid问题
很简单的.
function SelectOnea()
{
var lst1=window.document.getElementById("Listbox1");
var lstindex=lst1.selectedIndex;
if(lstindex<0)
return;
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
}
我要是能把v,t的值取出来,估计我就有办法了
2005用document.all.btn.click();--不知道为什么__doPostBack在2005上不能用了。
……
var isIE = true;
if(window.XMLHttpRequest)
{
isIE = false;
}
var xmlHttp;
function GetXMLHttpRequest()
{
return isIE ? new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
}
function calXMLHTTP()
{
var szUrl ="http://xxx.com/bbb.asmx?para=nnn";
var oHttp = GetXMLHttpRequest();
oHttp.open("GET", szUrl, false);
oHttp.send();
return oHttp.ResponseText;
}
……或者使用——
new ActiveXObject("ADODB.Connection")结合new ActiveXObject("ADODB.RecordSet")使用
<input id=hidbtn runat=server>在后台给listbox1添加属性
listbox.item.attribute.add("onclick","__doPostBack('hidbtn','')");写上隐藏button的onclick事件
private hidbtn_onclick(...)
{
去数据库搜数据赋值给listbox2;
}大概是这样,明白吗?
可以在页面中加入一个iframe,高宽设置为0,当listbox1中值变化时,把变化的值提交到iframe中,在后台通过Form方式得到此值。再查询数据库,得到listbox2中值范围,在后台注册一段脚本函数,循环把这些值添加到listbox2中,实际联动并且无刷新。
//***POST
ASCIIEncoding encoding=new ASCIIEncoding();
string reuqesturl = "http://adasd.com/asd.aspx";
string postdata = "xxxxx";
byte[] data = encoding.GetBytes(postdata);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);
myRequest.Method = "POST";
//myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(),Encoding.Default);
string content = reader.ReadToEnd();
Console.WriteLine("Get response from server:"+content);
myResponse.Close();
...//***GET
// web request
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);
myRequest.Credentials = CredentialCache.DefaultCredentials;
//myRequest.Method = "GET";
//myRequest.ContentType="application/x-www-form-urlencoded";
// Get response
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
string flag = new StreamReader(response.GetResponseStream()).ReadToEnd();
HttpStatusCode code = response.StatusCode;
string logtxt = "response status="+code.ToString()+" flag="+flag;
Console.WriteLine(logtxt);
...