执行以下代码时,我得到此错误。请帮忙。
Dim sb1 As New System.Text.StringBuilder
sb1.Append("<script type='text/javascript' language='javascript'>")
sb1.Append("window.open('../reports/Receipt.aspx?receiptno=" & Me.txtReceiptNo.Text.Trim & "&payorno=" & Me.txtPHospitalNo.Text.Trim & "&payorname=" & Me.txtPName.Text.Trim.Replace("'", """") & "&totalamount=" & amt & "&inwords=" & inwords & "&paytype=" & ddlPaymentType.SelectedItem.Text & "&payref=" & txtRef.Text.Trim & "&user=" & ViewState("username") & "&type=2&datecollected='" & datecollected & "'&company=" & company & "&roleid=" & ViewState("RoleId") & "&isRefund=false")
sb1.Append("','EncounterForm','toolbar=no,menubar=no,location=no');")
sb1.Append("</script>")
ScriptManager.RegisterStartupScript(Page, Me.GetType, "test", sb1.ToString, False)
答案 0 :(得分:0)
如果我稍稍更改了您的代码(因为我没有您的变量):
Dim tDummy As String = "coucou"
Dim sb1 As New System.Text.StringBuilder
sb1.Append("<script type='text/javascript' language='javascript'>")
sb1.Append("window.open('../reports/Receipt.aspx?receiptno=" & tDummy & "&payorno=" & tDummy & "&payorname=" & tDummy & "&totalamount=" & tDummy & "&inwords=" & tDummy & "&paytype=" & tDummy & "&payref=" & tDummy & "&user=" & tDummy & "&type=2&datecollected='" & tDummy & "'&company=" & tDummy & "&roleid=" & tDummy & "&isRefund=false")
sb1.Append("','EncounterForm','toolbar=no,menubar=no,location=no');")
sb1.Append("</script>")
我得到以下内容-无效-用Javascript(&datecollected='coucou'&
)输出:
<script type="text/javascript" language="javascript">
window.open('../reports/Receipt.aspx?receiptno=coucou&payorno=coucou&payorname=coucou&totalamount=coucou&inwords=coucou&paytype=coucou&payref=coucou&user=coucou&type=2&datecollected='coucou'&company=coucou&roleid=coucou&isRefund=false','EncounterForm','toolbar=no,menubar=no,location=no');
</script>
您将不得不转义或删除用作字符串定界符的多余单引号:
<script type="text/javascript" language="javascript">
window.open('../reports/Receipt.aspx?receiptno=coucou&payorno=coucou&payorname=coucou&totalamount=coucou&inwords=coucou&paytype=coucou&payref=coucou&user=coucou&type=2&datecollected=coucou&company=coucou&roleid=coucou&isRefund=false','EncounterForm','toolbar=no,menubar=no,location=no');
</script>