2

我对 JavaScript 和 jQuery 都很陌生,在我的 Visual Studio 代码中,它的说法是预期接近var se,而且它说'}'预期接近{"URL":window.location.href,}什么是合适的解决方案。

请指教。

这是我的代码:

<script type = "text/javascript">
        function renderSurvey(URL){
        var se = new SurveyEmbed("FM9wg_ghhgvjh","https://formsss.tester.com/","https://jhbjh.kjbkjedge.net/mfpembedconkhtweu/");
        var context = {"URL":window.location.href,};se.renderButton( context);
        }
    </script>
4

2 回答 2

1

There is nothing actually wrong with your code, my Visual Studio Code also doesn't give any errors.

You can improve on readability though, I think something like this is way cleaner (other people might disagree):

function renderSurvey(URL) {
  let se = new SurveyEmbed(
    "FM9wg_ghhgvjh",
    "https://formsss.tester.com/",
    "https://jhbjh.kjbkjedge.net/mfpembedconkhtweu/"
  );
  let context = { URL: window.location.href };

  se.renderButton(context);
}
于 2019-11-29T19:53:05.867 回答
0

您的语法没有问题,Visual Studio Code 是错误的(Taplar 指出的尾随逗号是允许的)。尝试在网络浏览器中运行您的代码——它是否按预期工作?如果没有,请打开浏览器的调试控制台并告诉我们您看到的错误。

于 2019-11-29T19:45:11.770 回答