本人是菜鸟遇到一个参数传递的问题,希望各位高手不吝赐教!
············JS部分···············
<script LANGUAGE=JavaScript>
function callServer() {
var u_name = document.getElementById("gjc").value;
if ((u_name == null) || (u_name == "")) return;
var url = "call.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null); }function updatePage() {
if (xmlHttp.readyState < 4 ) {
test.innerHTML="正在载入"; }
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
test.innerHTML=response; }
}
</script><script language="javascript" type="text/javascript">
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
</script>
···········JS部分结束··············----------------------ASP部分-------------------------<table width="100%" border="0" cellpadding="0" cellspacing="0">
<%sql=" select cp.*,yp.* from cp,yp where cp.yp_id=yp.id "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof
biaohao=rs("yp.id")
jmid="test"&bianhao (注:这里对层进行动态的命名)
%>
<tr>
<td align="center">
<a href="javascript:void(0)" onMouseOver="callServer();" >载入相同产品</a><span id="<%=jmid%>"></span>
</td>
</tr>
<%
loop
rs.movenext
rs.close()
set rs=nothing
%>
</table>----------------------ASP部分结束---------------------
jmid="test"&bianhao (注:这里对层进行动态的命名)
biaohao=rs("yp.id") 取得ID号问题:
1、如何将动态命名的<span id="<%=jmid%>"></span>中的 jmid 这个参数 通过callServer();这个函数传给updatePage() ,从而使test.innerHTML=response;中的test的名称都变为 jmid 这个动态参数 即实现 jmid.innerHTML=response; 这中间参数怎么传递2、biaohao=rs("yp.id")作为参数callServer(biaohao);传递过去后,在callServer()这个函数中如何取得他的值:
var bianhao = bianhao.value; 这样对吗
本人是菜鸟,希望好心的朋友能帮忙,急用,如果说叫我去看书之类的回答或者觉得问题太简单不愿意回答的朋友请绕道,谢谢,因为我现在急用,希望能得到切实有效的回答,万分感谢!!
············JS部分···············
<script LANGUAGE=JavaScript>
function callServer() {
var u_name = document.getElementById("gjc").value;
if ((u_name == null) || (u_name == "")) return;
var url = "call.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null); }function updatePage() {
if (xmlHttp.readyState < 4 ) {
test.innerHTML="正在载入"; }
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
test.innerHTML=response; }
}
</script><script language="javascript" type="text/javascript">
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
</script>
···········JS部分结束··············----------------------ASP部分-------------------------<table width="100%" border="0" cellpadding="0" cellspacing="0">
<%sql=" select cp.*,yp.* from cp,yp where cp.yp_id=yp.id "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof
biaohao=rs("yp.id")
jmid="test"&bianhao (注:这里对层进行动态的命名)
%>
<tr>
<td align="center">
<a href="javascript:void(0)" onMouseOver="callServer();" >载入相同产品</a><span id="<%=jmid%>"></span>
</td>
</tr>
<%
loop
rs.movenext
rs.close()
set rs=nothing
%>
</table>----------------------ASP部分结束---------------------
jmid="test"&bianhao (注:这里对层进行动态的命名)
biaohao=rs("yp.id") 取得ID号问题:
1、如何将动态命名的<span id="<%=jmid%>"></span>中的 jmid 这个参数 通过callServer();这个函数传给updatePage() ,从而使test.innerHTML=response;中的test的名称都变为 jmid 这个动态参数 即实现 jmid.innerHTML=response; 这中间参数怎么传递2、biaohao=rs("yp.id")作为参数callServer(biaohao);传递过去后,在callServer()这个函数中如何取得他的值:
var bianhao = bianhao.value; 这样对吗
本人是菜鸟,希望好心的朋友能帮忙,急用,如果说叫我去看书之类的回答或者觉得问题太简单不愿意回答的朋友请绕道,谢谢,因为我现在急用,希望能得到切实有效的回答,万分感谢!!
楼主可以在页面上写一个隐藏域<input type="hidden" id="aa" value="<%=jmid%>">
然后可以在js里先得到jmid的值 var jmid=document.getElementById("aa").value;
然后把test.innerHTML="正在载入";
改成document.getElementById(jmid).innerHTML="正在载入";
var jmid=document.getElementById("aa").value;
你这个aa名称是固定的,不是变量这样取值就会出问题了还是希望我上面2个问题有高手能给回答一下,谢谢
那可以这样
function callServer(dom) {
while(dom.nextSibling.nodeType != 1) {
dom = dom.nextSibling;
}
alert(dom.nextSibling.id) //这个就是你要的jmid
}<a onmouseover="callServer(this)">
2、biaohao=rs("yp.id")作为参数callServer(biaohao);传递过去后,在callServer()这个函数中如何取得他的值:
var bianhao = bianhao.value; 这样对吗这个就不用回答了吧。第一个可以解决了对吧
dom = dom.nextSibling;
不起作用,测试没反应。<a href="javascript:void(0)" onMouseOver="callServer();" >载入相同产品</a><span id="<%=jmid%>"></span> 我的 onMouseOver="callServer();" 这个是在<span>前面的我是这样的
a href="javascript:void(0)" onMouseOver="callServer(<%=jmid%>);" >载入相同产品</a><span id="<%=jmid%>"></span> 但是dom = dom.nextSibling;获取不到值
你调用的时候必须
callServer(this)这样然后你的函数定义的时候需要function callServer(dom)
<a href="javascript:void(0)" onMouseOver="callServer(<%=jmid%>);" >载入相同产品</a><span id="<%=jmid%>"></span>这里callServer(<%=jmid%>);" <%=jmid%>如何在function callServer(xx)里
定义一个变量获取xx的值
(id名称).innerHTML=response;才能把内容对应的显示出来,麻烦你看一下那段ASP代码,您应该就明白了,要不然说了半天浪费你时间还是对不上,谢谢
function callServer(xx) {
tmp = document.getElementById(xx);
var u_name = document.getElementById("gjc").value;
if ((u_name == null) || (u_name == "")) return;
var url = "call.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null); }function updatePage() {
if (xmlHttp.readyState < 4 ) {
tmp.innerHTML="正在载入"; }
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
tmp.innerHTML=response; }
}
我把我下面那部分也贴上
<a href="javascript:void(0)" onClick="callServer(<%=jmid%>);" >载入相同产品</a><span id="<%=jmid%>"></span>