简体   繁体   中英

Unterminated string constant javascript

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 constant however 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

You do not set the searchBoxLinkId and category variables.

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 input and category is set to 11111 . When you click on a tag, you redirect to that address.

<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>

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.

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