范例:
//返回一个异步结果
function getAjax(url,strtype,strvalue){
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",url+"?strtype="+strtype+'&strvalue='+strvalue+'&random='+Math.random(),false);
xmlhttp.send();
return xmlhttp.responseText;
}
//半成品出库表单,有了半成品序号显示半成品的名称、长度、重量、提示,用于替换show_seinfo(obj)函数
function show_seinfo2(obj){
seid=obj.value.trim();
var oTr=obj;
//循环直到找到tr 不能通过焦点法获取行号,因为此时失去焦点
for(var i=0;oTr.tagName.toLowerCase()!="tr";i++){
oTr=oTr.parentNode;
}
var trline=oTr.rowIndex - 1;
var objs_sename=document.getElementsByName("SeName");
var objs_selength=document.getElementsByName("SeLength");
var objs_seweight=document.getElementsByName("SeWeight");
var objs_note=document.getElementsByName("Note");
if(seid == ""){
//编码为空,清空该行的数据
objs_sename[trline].value = "";
objs_selength[trline].value= "";
objs_seweight[trline].value= "";
objs_note[trline].value= "";
}
else {
objs_sename[trline].value = getAjax('show_painfo2.asp','paname',seid);
objs_selength[trline].value = getAjax('show_painfo2.asp','palength',seid);
objs_seweight[trline].value = getAjax('show_painfo2.asp','paweight',seid);
objs_note[trline].value = getAjax('show_painfo2.asp','panote',seid);
}//else结束
}