如何从vbscript调用javascript函数

时间:2011-05-23 09:48:01

标签: javascript vbscript

如何从vbscript调用javascript函数。 我这样写了

<script type="text/vbscript">
jsfunction()
</script>
<script type="text/javascript">
function jsfunction()
{
  alert("Hello")
}
</script>

但它显示类型错误匹配如何实现它。请帮帮我。

谢谢你, 米希尔

4 个答案:

答案 0 :(得分:8)

假设你想要这个客户端而不是ASP;

如果将之前的JScript块放置在VBScript块之前(或将调用连接到加载事件),那么它将正常工作。 (当然只有IE)

...
<head>

<script type="text/vbscript">
     function foo
         call jsfunction()
     end function
</script>

<script type="text/javascript">
     function jsfunction()
     {
       alert("hello");
     }
</script>

</head>

<body onload="foo()">
...

答案 1 :(得分:3)

从Javascript调用VBScript函数 你的VBScript:

Function myVBFunction()
  ' here comes your vbscript code
End Function

您的Javascript:

function myJavascriptFunction(){
  myVBFunction();           // calls the vbs function
}
window.onload = myJavascriptFunction;
Alternatives (incompatible in some IE versions):


  // This one:
window.onload = function(){ myVBFunction(); }
  // This will also work:
window.onload = myVBFunction();
  // Or simply:
myVBFunction(); 
  // From a hardcoded link, don't write a semicolon a the end:
<a href="#" onclick="VBscript:myVBFunction('parameter')">link</a>    

反转: 从VBScript调用Javascript函数

Function myVBFunction()
  myJavascriptFunction()  
End Function

答案 2 :(得分:2)

试试这个......

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" >
function jsfunction()
{
  alert("Hello")
}

</script>
<%
Response.Write "Calling =" jsfunction() "."
%>
</BODY>
</HTML>

答案 3 :(得分:1)

我们应该编写return而不是alert,而return又使用response.write -

打印页面上的值

代码在下面 -

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" runat="server">
function test() {
return "Test";
}
</script>
<%
Response.Write "Value returned =" & test() & "."
%>
</BODY>
</HTML>