简体   繁体   中英

How can I use vb.net in javascript

I have question about use vb.net in javascript.

<script runat="server">
    Dim x As String
    Function Addx(ByVal txt As String) As String
        x = txt
        Return x
    End Function
</script>

I use function "Addx" in javascript like this.

<script language="javascript" type="text/javascript>
    var Getx = "<%=Addx('Hello World') %>";
    alert(Getx);
</script>

But it does not work and has an error.

Argument not specified for parameter 'txt' of 'Public Function Addx(txt As String) As String

What can I do?

VB doesn't allow single quotes for strings. JavaScript does. So, switch them around, and it should work.

<script language="javascript" type="text/javascript">
    var Getx = '<%=Addx("Hello World") %>';
    alert(Getx);
</script>

Edit: Also, make sure to close your quotes in your script tag attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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