早上好,
在网站中,您可以包含my project中的iFrame以显示信息:
<link rel="stylesheet" href="https://example.de/static/css/embedded.css">
<div class="alert alert-secondary">
<div class="ce_text"></div>
<button id="ce_openOverlay" class="btn btn-church" style="background-color: #800040" data-domain="test.example.de" data-ce_eventid="1">book now</button>
<div id="ce_overlay">/div>
</div>
<script src="https://example.de/static/js/embedded.js"></script>这也很好用,除了一件小事。也就是说,用户当然可以在他的页面上包含几个这样的代码片段。在embedded.js中,当页面加载时,我使用"data-ce_eventid“自动加载覆盖图的适当信息:
if (!window.jQuery) {
var script_tag_jquery = document.createElement('script');
script_tag_jquery.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.js');
var script_tag_accounting = document.createElement('script');
script_tag_accounting.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.4.1/accounting.min.js');
document.head.appendChild(script_tag_accounting);
document.head.appendChild(script_tag_jquery);
window.onload = function () {
var ce_domain = $('#ce_openOverlay').data('domain');
var ce_eventid = $('#ce_openOverlay').data('ce_eventid');现在我怎样才能确保在var ce_eventid中只有脚本标记上面的按钮的eventid在里面,而不是下面的按钮呢?
发布于 2020-11-03 18:16:21
检查这个问题:How may I reference the script tag that loaded the currently-executing script? first answer suggest document.currentScript,所以使用这个你会得到:
var div = $(document.currentScript).prev();
if (div.hasClass('alert')) {
// your code
}https://stackoverflow.com/questions/64658847
复制相似问题