如何从 vbscript 调用 javascript 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6095502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:13:05  来源:igfitidea点击:

How to call javascript function from vbscript

javascriptvbscript

提问by Mihir

how to call javascript function from vbscript. i wrote like this

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

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

but it is showing that type mis match how to achieve it. please help me.

但它表明类型不匹配如何实现它。请帮我。

Thank you, Mihir

谢谢你,米希尔

采纳答案by sgokhales

Try this ...

尝试这个 ...

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

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

回答by Alex K.

Assuming you want this client side as opposed to ASP;

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

If you place the JScript block beforethe VBScript block (or wire the call to a load event) that will work fine. (IE only of course)

如果您将 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()">
...

回答by bulevardi

Calling a VBScript function from Javascript Your VBScript:

从 Javascript 调用 VBScript 函数您的 VBScript:

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

Your Javascript:

你的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>    


Inversed: Calling a Javascript function from VBScript

反转:从 VBScript 调用 Javascript 函数

Function myVBFunction()
  myJavascriptFunction()  
End Function

回答by Umesh Chaurasiya

Instead of alert we should write return which is in turn print the values on page using response.write-

我们应该写返回而不是警报,它反过来使用 response.write- 在页面上打印值

code is below -

代码如下 -

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