javascript应该怎么写呢,我用下面的document.write语句始终输出不了...,用了document.getElementById("i.
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
3 个解决方案
#1
把runat="server"去掉,可以输出值了,但输出的值仍然是初始化的值,而不是函数执行后的返回值(函数正常执行了),window.onload=function(){}不是在页面加载之前执行吗,为什么在页面里document.write不是输出的window.onload执行后的值呢?
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
#2
ajax!!!
#3
调用后台的方法。
#1
把runat="server"去掉,可以输出值了,但输出的值仍然是初始化的值,而不是函数执行后的返回值(函数正常执行了),window.onload=function(){}不是在页面加载之前执行吗,为什么在页面里document.write不是输出的window.onload执行后的值呢?
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript" runat="server">
var s = 0;
var m = 1;
var t = 0;
function doTest()
{
var test = new ActiveXObject('VBActiveXTest.VBTest');
s = test.Start();
alert(s);
m = test.GetCount();
alert(m);
t = test.StopService();
alert(t);
}
window.onload=function(){
doTest();
}
</script>
</HEAD>
<BODY>
<input type="button" value="调用" id="btnOK" onclick="doTest();"></input>
<script language="javascript">
document.write("<p>"+s+"</p>");
document.write("<p>"+m+"</p>");
document.write("<p>"+t+"</p>");
</script>
</BODY>
</HTML>
#2
ajax!!!
#3
调用后台的方法。