【问题标题】:pass the js variable variable to html template将js变量变量传递给html模板
【发布时间】:2017-08-22 11:38:17
【问题描述】:

我已经在 js 文件中获取了 drupal 值。我想在 html 模板中传递变量。我想将 'anniversaryCount' 包含到 html 模板中。现在我抓住了

未捕获的 SyntaxError: 无效的正则表达式: /(^|.)cbox(.|$)/: 堆栈溢出 在 RegExp.test()

(function ($) {
  Drupal.behaviors.one_time_popup = {
    attach: function (context, settings) {
      var anniversaryCount = Drupal.settings.one_time_popup.aniv;
      console.log(anniversaryCount); //prints correct value
      cardTemplate = "<div class='cardTemplate'><span class='birthdayImage'></span><p class='wishes'>Happy Work Anniversary <span id='spl_name'></span> !</p><img src='" + Drupal.settings.publicpath + "/Anniversary_Images/" + anniversaryCount + "Anniversary.jpg'></div>";
    }
  };
}(jQuery));

【问题讨论】:

  • 您的错误与您的代码无关,此错误参考 RegExp /(^|.)cbox(.|$)/

标签: javascript html drupal drupal-7


【解决方案1】:

用 jquery 把你的 html 放到页面中

$("#your_elemen_id_where_to_put_html").html(cardTemplate);

【讨论】:

    猜你喜欢
    • 2017-11-10
    • 2020-10-23
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2018-04-07
    • 2019-04-03
    • 2011-05-08
    相关资源
    最近更新 更多