简体   繁体   English

在VBScript中调用JS函数

[英]Calling JS function in VBScript

Hi am trying to get the textbox value of one asp page to other asp page and set the value here is VBScript which it does 您好我正在尝试将一个asp页面的文本框值获取到其他asp页面,并将此值设置为VBScript

If(disableListHeaderPR()) Then
    bEnablePRField = false
Else
    bEnablePRField = true
End If 

Here disableListHeaderPR() is JS function. 这里disableListHeaderPR()是JS函数。 I am getting error saying Variable is undefined: 'disableListHeaderPR' Here is the JS function code 我收到错误,说变量未定义:'disableListHeaderPR'这是JS函数代码

function disableListHeaderPR()
{
    if(dateDifference(document.getElementById("txtCommDte").value, "05/04/2012") < 0 ) 
    {
        return false;
    }
    else
    {
        return true;
    } 
}

This page has info on calling vbs from js and vice-versa. 此页面包含从js调用vbs的信息,反之亦然。

http://www.webdeveloper.com/forum/archive/index.php/t-49920.html http://www.webdeveloper.com/forum/archive/index.php/t-49920.html

But do keep in mind that as long as you are using VBScript, your app won't run as expected in any browser other than IE. 但请记住,只要您使用VBScript,您的应用程序将无法在IE以外的任何浏览器中按预期运行。

My solution would be to set your variable in the VBScript server-side and then flush the result out to the page in a different JavaScript function that calls your other JavaScript function. 我的解决方案是在VBScript服务器端设置变量,然后在调用其他JavaScript函数的不同JavaScript函数中将结果刷新到页面。 Sample (untested) as follows: 样品(未经测试)如下:

<%
    Dim bEnablePRField
    bEnablePRField = Request.Form("checkboxEnablePRField") <> ""
%>
<script type="text/javascript">
    function EnablePRField() {
        if (<%=bEnablePRField%> === 'False') {
            disableListHeaderPR();
        }
    }
    function disableListHeaderPR() {
            if (dateDifference(document.getElementById("txtCommDte").value, "05/04/2012") < 0 ) {
                return false;
            } else {
                return true;
            } 
    }
</script>

Something very similar to that should work for you. 与此非常相似的东西应该适合你。

I feel I should point out that, for Classic ASP, the VBScript is only processed server-side so this should work in any browser that supports JavaScript. 我觉得我应该指出,对于Classic ASP,VBScript只在服务器端处理,所以这应该适用于任何支持JavaScript的浏览器。 Before I switched to .Net, I used to pull this trick a lot, and it worked fine in Firefox, as well as IE. 在我切换到.Net之前,我经常使用这个技巧,它在Firefox和IE中运行良好。

Should you wish instead to use the results of your JavaScript function in your VBScript function, simply store the results of the JavaScript function in a hidden field (eg, <input id="myResults" name="myResults" type="hidden" /> ) and then access the value in VBScript (eg, Request.Form("myResults" ). 如果您希望在VBScript函数中使用JavaScript函数的结果,只需将JavaScript函数的结果存储在隐藏字段中(例如, <input id="myResults" name="myResults" type="hidden" /> )然后访问VBScript中的值(例如, Request.Form("myResults" ))。

You can also use the hidden field if you are mixing VBScript and JavaScript on the client-side. 如果要在客户端混合使用VBScript和JavaScript,也可以使用隐藏字段。 Just change the way you access the hidden field in VBScript (eg, document.form("myForm").myResults.value ). 只需更改访问VBScript中隐藏字段的方式(例如, document.form("myForm").myResults.value )。

Finally, I cannot agree more with techfoobar . 最后,我对techfoobar表示赞同 If you are mixing VBScript and JavaScript on the client-side, then the only browser it will work in is IE and I would also strongly recommend switching over entirely to JavaScript. 如果你在客户端混合VBScript和JavaScript,那么它将使用的唯一浏览器是IE,我也强烈建议完全切换到JavaScript。

Hope this helps, 希望这可以帮助,

Pete 皮特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM