如何逃脱两次qoutes。甚至尝试“ \”,但在控制台中看起来很糟糕。那为什么它不起作用
var vimeo;
' <span class="play-button button" data-vimeo-id="'+ vimeo +'" data-vimeo-iframe="<iframe src="https://player.vimeo.com/video/'+ vimeo +'?dnt=1&app_id=122963" width="1920" height="1080" frameborder="0" title="bla bla" allow="autopla; fullscreen" allowfullscreen></iframe>" Play </span>'
输出
答案 0 :(得分:0)
您可以使用Typescript template strings,假设iframe字符串只是在以后检索(使用decodeURIComponent
):
var vimeo;
var iframe = encodeURIComponent('<iframe src="https://player.vimeo.com/video/' + vimeo + '?dnt=1&app_id=122963" width="1920" height="1080" frameborder="0" title="bla bla" allow="autopla; fullscreen" allowfullscreen></iframe>');
var s = `<span class="play-button button" data-vimeo-id="${vimeo}" data-vimeo-iframe="${iframe}"> Play </span>`;
var element = document.createElement('div');
element.innerHTML = s;
document.body.append(element);
console.log(decodeURIComponent(document.getElementsByClassName('play-button')[0].getAttribute('data-vimeo-iframe')))
答案 1 :(得分:-1)
尝试一下:
var vimeo;
`<span class="play-button button" data-vimeo-id="${vimeo}" data-vimeo-iframe="<iframe src="https://player.vimeo.com/video/${vimeo}?dnt=1&app_id=122963" width="1920" height="1080" frameborder="0" title="bla bla" allow="autopla; fullscreen" allowfullscreen></iframe>" Play </span>`