我有一个用VBScript编写的框架。在这个框架中的一些函数中,在If语句中检查函数的参数是否为空,然后执行一些操作。使用Javascript编写的框架的代码。所以我不需要向函数传递任何东西来执行某些操作。在IE8和更早的版本中,下一步工作方法是:
<script type="text/vbscript">
Function Test(val)
If (IsNull(val)) Then
Test = "Null"
ElseIf (IsObject(val)) Then
If (val Is Nothing) Then
Test = "Nothing"
End If
End If
End Function
Dim jsNothing
Set jsNothing = Nothing
msgBox(Test(jsNothing))
msgBox(Test(Null))
</script>
<script type="text/javascript">
alert(Test(jsNothing));
</script>
在IE <9中,输出将为: Nothing,Null,Nothing。
在IE9: Nothing,Null,Null。
如何在IE9中从Javascript向VBScript传递任何内容?
抱歉,我知道很难看,但我被困住了。并且讨厌VBScript。
edit:有一个框架函数的例子。我不能改变它,因为它在应用程序中被广泛使用。
Function ExampleFunction(val)
If (val Is Nothing) Then
ExampleFunction = 1
Else
ExampleFunction = 0
End If
End Function
更新
辞职吧。找到了一个更好的。
发布于 2012-02-17 00:37:15
不幸的是,你可能被困在这里了-- JavaScript没有“什么都没有”的等价物。有关详细信息,请参阅This Article。
但是,以下内容可能会起作用。在您的VBScript中创建一个名为"GetNothing“的函数,该函数返回"Nothing”。在您的JavaScript中使用"var jsNothing = GetNothing()“。来自this article
发布于 2014-10-25 01:00:16
这个问题很有趣,我想我会试着回答它,只是为了好玩。
(恭喜mixel找到一份更好的工作!)
我现在不能访问IE,所以我不能测试它,但是如果你试着写一个这样的函数会怎么样:
<script type="text/vbscript">
Function CallWithNulls(fn, arg1, arg2, arg3)
If (isNull(arg1)) arg1 = Nothing
If (isNull(arg2)) arg2 = Nothing
If (isNull(arg3)) arg3 = Nothing
fn(arg1, arg2, arg3)
End Function
Function IsNothing(arg1, arg2, arg3)
return arg1 is Nothing
End Function
</script>
<script type="text/javascript">
alert(CallWithNulls(IsNothing, null, 1, 2));
</script>
当然,我不知道VB脚本是否允许调用这样的函数...你将不得不处理更多/更少的争论。
发布于 2011-09-28 14:56:13
使用一个像零甚至负数这样的值,这将允许您简单地使用错误的计算,这样您就不必担心不同的浏览器及其在计算NULL
对象时的怪癖。
https://stackoverflow.com/questions/7568471
复制相似问题