admin管理员组

文章数量:1279181

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

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

Share Improve this question edited Sep 9, 2014 at 10:55 user3414693 asked Sep 9, 2014 at 10:54 user3956534user3956534 831 gold badge1 silver badge7 bronze badges 4
  • you have some heavy typos in your code, check the double quotes – john Smith Commented Sep 9, 2014 at 10:56
  • Look at the colors in the code above, and see if you can't spot it, it has something to do with the quotes. – adeneo Commented Sep 9, 2014 at 10:56
  • because I am doing this in a sharepoint display template and as I have created my own function, it won't be defined in the ctx, so can't be run by just putting the function name – user3956534 Commented Sep 9, 2014 at 11:10
  • if you know how to do this in sharepoint please tell me – user3956534 Commented Sep 9, 2014 at 11:11
Add a ment  | 

2 Answers 2

Reset to default 5

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.

本文标签: htmlUnterminated string constant javascriptStack Overflow