jquery - html中的正则表达式不匹配

标签 jquery html css

我在 js 文件的变量卡中有一段 html 代码。我在卡变量错误中发现正则表达式不匹配。所有单引号和双引号都匹配。我在 html block 中做错了什么。是否有拼写错误。

(function ($) {
Drupal.behaviors.one_time_popup = {
attach: function (context, settings) {
var celeType=Drupal.settings.one_time_popup.celeType;
 card="<div class=\'cardTemplate-aniv\'> 
 <p class=\'bir-anniv-wishes\'>Happy Birthday and Successful Anniversary</p>
 <p id=\'aspirian-name\'>"+userName+"</p>
 <img src=\'"+Drupal.settings.publicpath+"/Birthday_Images/birthdayTemplate1.jpg\' style=\'width:250px;height:230px;\'>
 <img src=\'"+Drupal.settings.publicpath+"/Anniversary_Images/"+anniversaryCount+"Anniversary.jpg\' style=\'width:250px;height:250px;\'>
</div>";
 }
};
}(jQuery)); 

我还有一个模板

 cardTemplate1 = "<div class=\'cardTemplate\'><span class=\'birthdayImage\'></span><p class=\'wishes\'>Happy Birthday <span id=\'aspirian-name\'>"+userName+"</span> !</p><img src=\'"+Drupal.settings.publicpath+"/Birthday_Images/birthdayTemplate1.jpg\'></div>";

显示没有转义单引号的正则表达式不匹配

最佳答案

双引号中不能包含多行字符串文字。如果你有 ES6,你可以使用反引号来获得多行模板字符串。参见 creating-multiline-strings-in-javascript

关于jquery - html中的正则表达式不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45952533/

相关文章:

javascript - 替代javascript中的多个if else语句

javascript - 如何在进一步执行 js 之前从循环中收集 $.get 的所有结果

jquery 选择器字符和数字正则表达式

html - 图片链接和悬停在 ie 中不起作用

javascript - 为什么 naturalHeight 或 naturalWidth 返回 `undefined` ?

android - 使用 TalkBack 或 VoiceOver 时样式居中的复选框不可选中

javascript - 数据属性的 jQuery 自定义事件

javascript - 完全摆脱图标

html - 为什么最小化的聊天框在飞?

c# - Css 每行显示 3 个 foreach 结果