日期:2014-05-17  浏览次数:20798 次

这段JS奇怪
JScript code

<script>
var rightAd;

rightAd = '<table width="90" border="0" cellpadding="0" cellspacing="0 "  ><tr><td align=middle valign=middle><A HREF=http://www.r6988.com target=_blank><IMG SRC=http://www.xunying.com/gg/pics/otherweb/2009101209480271131.gif WIDTH=80 HEIGHT=80 BORDER=0 ALT=r6988></A></td></tr><tr><td height=10></td></tr><tr><td align=middle valign=middle><A HREF=http://www.t8877.com target=_blank><IMG SRC=http://www.xunying.com/gg/pics/otherweb/2009101410390855042.gif WIDTH=80 HEIGHT=80 BORDER=0 ALT=t8877></A></td></tr><tr><td height=10></td></tr><tr><td align=middle valign=middle><A HREF=http://www.zq9393.com target=_blank><IMG SRC=http://www.xunying.com/gg/pics/otherweb/2009102113370472914.gif WIDTH=80 HEIGHT=80 BORDER=0 ALT=zq9393></A></td></tr><tr><td height=10></td></tr><tr><td align=middle valign=middle><A HREF=http://www.y080.net/ target=_blank><IMG SRC=http://www.xunying.com/gg/pics/otherweb/2009101601342754562.gif WIDTH=80 HEIGHT=80 BORDER=0 ALT=y080></A></td></tr></table>';

document.ns = navigator.appName == "Netscape"
function PM_floatDivMove(){
    divRight.style.top = (document.body.scrollTop + 80)+"px";
    divRight.style.left = (document.body.scrollLeft + document.body.clientWidth -90)+"px";

    setTimeout("PM_floatDivMove();",150);
}

if(document.ns)
{
    document.write('<div style="position:absolute" id="divRight">' + rightAd + '</div>');
}else{
    document.write('<div id="divRight" style="position:absolute;visibility:visible;z-index:0">' + rightAd + '</div>');
}
PM_floatDivMove();
</script>


这段JS就是一个JS文件,我想问的是rightAd 里面的值是怎么得到的,JS里面能读数据?

------解决方案--------------------
rightAd = ' <%= varTest%>';
后台代码对变量的定义需要是public。而且是全局的。js就按上面的获取
------解决方案--------------------
JScript code


var rightAd;
document.ns = navigator.appName == "Netscape"
function PM_floatDivMove(canshu){
var  rightAd =canshu;
    divRight.style.top = (document.body.scrollTop + 80)+"px";
    divRight.style.left = (document.body.scrollLeft + document.body.clientWidth -90)+"px";

    setTimeout("PM_floatDivMove();",150);
}

if(document.ns)
{
    document.write('<div style="position:absolute" id="divRight">' + rightAd + '</div>');
}else{
    document.write('<div id="divRight" style="position:absolute;visibility:visible;z-index:0">' + rightAd + '</div>');
}
PM_floatDivMove();
</script>

------解决方案--------------------
这样:
HTML code

<script type="text/javascript" >
var rightAd = "<%= varTest %> ";
</scrpit>
<script language="JavaScript" src="js/Ad.js"> </script>

------解决方案--------------------
这个是嵌入代码
用<%。。。%>
而不是用
<%=。。。%>

以下代码执行后页面查看源代码rightAd就等于你这个

HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head