ASP.NET调用JavaScript 这不容易吗 用 ajax 查询 然后赋值不就OK 了 A 的回车键事件 onkeypress = " query(); "在 function query(){ if (key == 49) 查数据库。} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 -.-初学者,完全不懂JS跟AJAX,还在学习中 <textbox id="txtCode" onkeypress="getName(event)"/><textbox id="txtName"/>function getAjax(){ var oHttpReq = null; if(window.ActiveXObject) oHttpReq = new ActiveXObject("MSXML2.XMLHTTP"); else if(window.createRequest) oHttpReq = window.createRequest(); else oHttpReq = new XMLHttpRequest(); return oHttpReq;}function isEnter(ev){ var ev = ev || window.event; var keycode; if(window.event) keycode = ev.keyCode; else keycode = ev.which; if(keycode == 10 || keycode == 13) return true; else return false;}function getName(ev){var ev = ev || window.event;if(!isEnter(ev)) return;var req = getAjax();req.open("GET", "test.aspx?code="+document.getElementById("txtCode").value, true);req.onreadystatechange = function(){if(req.readyState==4 || req.readyState=="complete"){var re = req.responseText;//test.aspx页面上多有点内容document.getElementById("txtName").value = re;document.getElementById("txtName").focus();}};req.send(null);}test.aspx.cspage_load(){string name = DB.GetValue("select name from a where code='"+Request["code"]+"'");Response.Write(name);//req.responseTextResponse.End();//必要的}细节自己处理 //创建xmlRequestfunction createXMLHttp(){ if (window.XMLHttpRequest) { var xmlObj = new XMLHttpRequest(); } else { var MSXML = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP']; for (var n = 0; n < MSXML.length; n++) { try { var xmlObj = new ActiveXObject(MSXML[n]); break; } catch(e) { } } } return xmlObj;}//根据 url 获取 xml数据字符串function getDataByXmlHttp(url){ var xmlhttp; var s = null; xmlhttp = createXMLHttp(); if (null != xmlhttp) { xmlhttp.open("get", url, false); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(); s = xmlhttp.responseText; } return s;}function query(){ if (key == 49) document.getElementById("B").value = getDataByXmlHttp(url) ;}url 为你请求的(查数据的)路径 + 参数 jquery无刷新问题------------请帮助 文字无缝滚动跨浏览器问题 关于jquery换行的问题 JS怎么把XML数据保存在服务器端? 如何修改flash新闻切换图片中的链接文字的颜色。 怎么用JS写跳出窗口 求助 图片滚动 DOM技术的cloneNode方法,不能把被复制的节点的状态也复制吗?? 光标移动(javascript)??? 再问一个问题:能否让文本框随着文字长短的变化而改变其长和宽全(或换行),使其在打印预览,文字多时不会出现滚动条。 如何在网页的onload事件执行之前先加载从外面引入的一段js 如何用JAVA实时刷新父页面链接里的变量?
<textbox id="txtName"/>
function getAjax()
{
var oHttpReq = null;
if(window.ActiveXObject)
oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
else if(window.createRequest)
oHttpReq = window.createRequest();
else
oHttpReq = new XMLHttpRequest();
return oHttpReq;
}
function isEnter(ev)
{
var ev = ev || window.event;
var keycode;
if(window.event) keycode = ev.keyCode;
else keycode = ev.which;
if(keycode == 10 || keycode == 13) return true;
else return false;
}
function getName(ev)
{
var ev = ev || window.event;
if(!isEnter(ev)) return;
var req = getAjax();
req.open("GET", "test.aspx?code="+document.getElementById("txtCode").value, true);
req.onreadystatechange = function(){
if(req.readyState==4 || req.readyState=="complete"){
var re = req.responseText;//test.aspx页面上多有点内容
document.getElementById("txtName").value = re;
document.getElementById("txtName").focus();
}
};
req.send(null);
}
test.aspx.cs
page_load()
{
string name = DB.GetValue("select name from a where code='"+Request["code"]+"'");
Response.Write(name);//req.responseText
Response.End();//必要的
}
细节自己处理
//创建xmlRequest
function createXMLHttp()
{
if (window.XMLHttpRequest) {
var xmlObj = new XMLHttpRequest();
}
else {
var MSXML = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
for (var n = 0; n < MSXML.length; n++) {
try {
var xmlObj = new ActiveXObject(MSXML[n]);
break;
}
catch(e) {
}
}
}
return xmlObj;
}
//根据 url 获取 xml数据字符串
function getDataByXmlHttp(url)
{
var xmlhttp;
var s = null;
xmlhttp = createXMLHttp();
if (null != xmlhttp)
{
xmlhttp.open("get", url, false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send();
s = xmlhttp.responseText;
}
return s;
}
function query(){
if (key == 49)
document.getElementById("B").value = getDataByXmlHttp(url) ;
}url 为你请求的(查数据的)路径 + 参数