简体   繁体   English

Javascript缺少分号,在哪里?

[英]Javascript missing semicolon, where?

I am using vb.net with javascript. 我正在将vb.net与javascript一起使用。 Whenever I click a link on page 1, it loads and opens page 2. As part of this, in the page_load I have a bit of code which registers a javascript function as below: 每当我单击第1页上的链接时,它将加载并打开第2页。作为此过程的一部分,在page_load中,我有一些代码注册了如下所示的javascript函数:

   Private Sub regjs()
        Dim requesttype = "xx"
        Dim url As String = "page.aspx?rtype=" & requesttype & "&claimid="

        Dim s As New StringBuilder
        s.Append("<script type=""text/javaScript"">")
        s.Append("var r = new Object();" & ControlChars.CrLf)
        s.Append("if (window.returnValue == 'undefined') { window.returnValue = ''; }" & ControlChars.CrLf)
        s.Append("function vt(param) { " & ControlChars.CrLf)
        s.Append("if (param !== null) {" & ControlChars.CrLf)
        ***s.Append("var jurl = '" & url & "'")
        s.Append("param;" & ControlChars.CrLf)***
        s.Append("var r = window.showModalDialog(jurl,'','dialogWidth:500px;dialogHeight:500px;resizable:no');" & ControlChars.CrLf)
        s.Append("}" & ControlChars.CrLf)
        s.Append("}" & ControlChars.CrLf)
        s.Append("</script>")

        If Not ClientScript.IsClientScriptBlockRegistered("js") Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "js", s.ToString())
        End If
    End Sub

I am getting an error saying there is a missing semicolon when the page attempts to load. 我收到一个错误消息,说页面尝试加载时缺少分号。 The error is occuring on the s.Append("param;" * ControlChars.CrLf) line saying there is a missing ";". 错误发生在s.Append(“ param;” * * ControlChars.CrLf)行上,提示缺少“;”。 Can anyone point out where I have gone wrong? 谁能指出我哪里出问题了? (I am trying to construct a url with a variable as a query string value). (我试图构造一个带有变量作为查询字符串值的url)。

Thanks, C 谢谢,C

That code outputs the following string: 该代码输出以下字符串:

<script type="text/javaScript">var r = new Object();
if (window.returnValue == 'undefined') { window.returnValue = ''; }
function vt(param) { 
if (param !== null) {
var jurl = 'page.aspx?rtype=xx&claimid='param;
var r = window.showModalDialog(jurl,'','dialogWidth:500px;dialogHeight:500px;resizable:no');
}
}
</script>

As you can see, this line is invalid: 如您所见,此行无效:

var jurl = 'page.aspx?rtype=xx&claimid='param;

I suspect that you intended to do a string concatenation there. 我怀疑您打算在此处进行字符串连接。

Also, it's worth mentioning that you should just use StringBuilder.AppendLine rather than Append with ControlChars.CrLf . 另外,值得一提的是,您应该只使用StringBuilder.AppendLine而不是使用ControlChars.CrLf Append

声明变量时,需要以分号结束语句。

s.Append("var jurl = '" & url & "'")
s.Append("param;" & ControlChars.CrLf)

builds the code 建立代码

var jurl = 'page.aspx?rtype=xx&claimId='param;
                                       ^

The string (and the statement) ends at the indicated point, but there is no semicolon. 字符串(和语句)在指定的点结束,但是没有分号。

One assumes you meant to add the param to the end of the string, in which case you are missing a + . 一个假设您打算将param添加到字符串的末尾,在这种情况下,您会丢失+

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

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