2015-12-10 71 views
-1

我写它打印这是由它通过JavaScript渲染点击一个按钮触发了DOM的某一区域的功能请参见下面的代码...获得“未捕获的SyntaxError:意外的标记}

function MarkQuiz() { 
    var CorrectAnswers = 0, 
     TotalQuestions = 0, 
     CurrentQuestion = "", 
     Percentage = 0, 
     Output = ""; 

    $("select").each(function(key,value) { 
     CurrentQuestion = "#" + $(value).attr("id"); 
     TotalQuestions = key + 1; 

     if($(CurrentQuestion).val() == "Correct") { 
      CorrectAnswers++; 
     } 
    }); 

    Percentage = (CorrectAnswers/TotalQuestions) * 100; 

    Output = "You Scored..." + 
      "<h1>"+Percentage+"%</h1>" + 
      "Which means you got " + CorrectAnswers + " out of " + TotalQuestions + " correct.<br/>" + 
      "<br/><a href='#' onclick='PrintCertificate('#QuizMainContent')' class='button' id='PrintCertificate'>Print your Certificate</a>"; 

    $("#QuizMainContent").html(Output); 
} 

function PrintCertificate(DOMArea) { 
    var PrintArea = $(DOMArea), 
    PrintWindow = window.open('',''); 
    PrintWindow.document.write($(PrintArea).html()); 
    PrintWindow.document.close(); 
    PrintWindow.focus(); 
    PrintWindow.print(); 
    PrintWindow.close(); 

} 

然而,当我点击该按钮,我收到此错误... enter image description here

这是URL到项目:http://historicalperiods.esy.es/

我在做什么错在ADVA 谢谢NCE。

+0

好心分享URL,因为它不是文件的问题,但带有URL –

+0

那么,当你点击它提供给你的方便链接时会出现什么代码? –

+0

错误消息说错误来自不同的文件。点击控制台中的链接转到该文件。 – Quentin

回答

1
<a href="#" onclick="PrintCertificate(" #quizmaincontent')'="" class="button" id="PrintCertificate">Print your Certificate</a> 

这是在您的HTML。这是什么导致了这个问题。正如你所看到的,你"打开属性,那么你在你的JavaScript函数中使用",并且可以在功能'关闭该参数,则关闭属性与',然后你做=""(这没有意义)。

的正确方法应该是:

<a href="#" onclick="PrintCertificate('#quizmaincontent')" class="button" id="PrintCertificate">Print your Certificate</a> 
+0

我仍然收到此错误。这是我所做的... \t \t \t'
Print your Certificate'; –

+0

您仍然打开'onclick =“”'属性,但也可以在函数中使用参数“'''将双引号(''')改为单引号(''')。像这样:'onclick =“PrintCertificate('#QuizMainContent')”' –

0

感谢您的帮助......

我一点点修改为L JA提供的答案纠正了这个...

'<br/><a href="#" onclick="PrintCertificate(\'#QuizMainContent\')" class="button" id="PrintCertificate">Print your Certificate</a>'; 
+0

你不**有**来逃避参数。因为你可以使用'''in''''因为它看到'''作为字符串的一部分,所以:'onclick =''“'工作,而'onclick =”“”'不起作用,因为第一个'“'关闭属性。 –

相关问题