未捕获的SyntaxError:Javascript中的意外标记

时间:2016-09-20 06:42:58

标签: javascript sharepoint sharepoint-2013

我正在尝试在我的调查中插入超链接我在此行中收到此错误var myspan1 = $(“span [title ='Laptop']”);

 <script>
 $(document).ready( function() {
 var myspan1 = $(“span[title=’Laptop’]”);
 myspan1.append(‘<a target=”_blank” style=”vertical-align:middle;       color:#0072c6″  href=”@http://doc/IT/IT%20Library/SP_UAT%20Server%20and%20Services%20Error.PNG” > <b>[Show]</b></a>’);
 });

3 个答案:

答案 0 :(得分:0)

正确使用单引号和双引号。试试这个

$(document).ready( function() {
    var myspan1 = $("span[title='Laptop']");
    myspan1.append("<a target='_blank' style='vertical-align:middle;color:#0072c6'  href='@http://doc/IT/IT%20Library/SP_UAT%20Server%20and%20Services%20Error.PNG'> <b>[Show]</b></a>");
});

答案 1 :(得分:0)

您的报价存在严重问题(混合单打和双打,甚至是无法识别的字符)。看看这个:

 $(document).ready( function() {
  var myspan1 = $("span[title=’Laptop’]");
  myspan1.append("<a target='_blank' style='vertical-align:middle; color:#0072c6'  href='@http://doc/IT/IT%20Library/SP_UAT%20Server%20and%20Services%20Error.PNG'> <b>[Show]</b></a>");
 });

答案 2 :(得分:0)

您的选择器出现问题 请检查此fiddle

$(document).ready( function() {
  var myspan1 = $('span[title="Laptop"]');
  myspan1.append("<a target='_blank' style='vertical-align:middle; color:#0072c6'  href='@http://doc/IT/IT%20Library/SP_UAT%20Server%20and%20Services%20Error.PNG'> <b>[Show]</b></a>");
 });