如何从vbscript调用javascript函数

发布于 2024-11-08 22:48:52 字数 278 浏览 0 评论 0原文

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

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

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

谢谢你, 米希尔

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

<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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

感性 2024-11-15 22:48:53

假设您想要此客户端而不是 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()">
...

Assuming you want this client side as opposed to ASP;

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

...
<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()">
...
一曲琵琶半遮面シ 2024-11-15 22:48:53

从 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

Calling a VBScript function from Javascript
Your VBScript:

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

Your 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

Function myVBFunction()
  myJavascriptFunction()  
End Function
装迷糊 2024-11-15 22:48:53

试试这个...

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

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

Try this ...

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

</script>
<%
Response.Write "Calling =" jsfunction() "."
%>
</BODY>
</HTML>
妄断弥空 2024-11-15 22:48:53

我们应该编写 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>

Instead of alert we should write return which is in turn print the values on page using 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文