Javascript 未终止的字符串常量javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25742812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 21:48:29  来源:igfitidea点击:

Unterminated string constant javascript

javascripthtmlonclick

提问by user3956534

onclick="var searchb = jQuery('#'+searchBoxLinkId).value; 
var searchlink= window.location.protocol + '//' + window.location.hostname+'/Dave2/Pages/FAQSearch.aspx?category='+category+'&k='+searchb;
window.location = searchlink;" href="javascript: {}">

I have added this line of code to my javascript/html but it gives me the error Unterminated string constanthowever I cannot see where the problem is. I have to do it this way as I am doing something in sharepoint and it seems like this way is the only way it will work

我已将这行代码添加到我的 javascript/html 但它给了我错误Unterminated string constant但是我看不到问题出在哪里。我必须这样做,因为我在 sharepoint 中做某事,而且似乎这种方式是唯一可行的方式

回答by elia07

You do not set the searchBoxLinkIdand categoryvariables.

您没有设置searchBoxLinkIdcategory变量。

We assume some existing HTML (such as the snippet below) will set the two variables. In the code below, you can enter some variable into inputand categoryis set to 11111. When you click on a tag, you redirect to that address.

我们假设一些现有的 HTML(例如下面的代码段)将设置这两个变量。在下面的代码中,您可以将一些变量输入inputcategory设置为11111. 当您单击标签时,您会重定向到该地址。

<html>
<head>
    <title></title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript">
        var category=11111;
    </script>
</head>
<body>
    <input type="text" id="searchBoxLinkId"/>
    <a onclick="var searchb = jQuery('#searchBoxLinkId').val(); var searchlink= window.location.protocol + '//' + window.location.hostname+'/Dave2/Pages/FAQSearch.aspx?category='+category+'&k='+searchb;window.location.href = searchlink;" href="#">eee</a>

</body>

回答by Nimesh khatri

You can use matching pairs of single or double quotation marks. Double quotation marks can be contained within strings surrounded by single quotation marks, and single quotation marks can be contained within strings surrounded by double quotation marks.

您可以使用匹配的单引号或双引号对。双引号可以包含在单引号包围的字符串中,单引号可以包含在双引号包围的字符串中。