在模态激发后替换文本

replace text after modal has fired

本文关键字:替换 文本 模态      更新时间:2023-12-08

我正试图通过模态中的jquery替换文本。当模态已经可见并打开,并且屏幕上显示文本"Change me"时,我的".replace"部分在控制台中工作得很好。但是,如果文本不可见,我就无法使其工作。我相信我们在用"揭秘"。有什么想法吗?

如果有帮助的话,模态通过点击按钮来触发。超时并不理想。

$("*").each(function () { 
    if ($(this).children().length == 0) { 
        $(this).text($(this).text().replace("Change me", "I have been changed"));
    } 
});
}

<div id="myModal" class="reveal-modal" style="visibility: visible">
    <div class="my-modal-content">
        <div class="myText">Change me</div>
    </div>
</div>

查看包含reveal.js模态插件的基础文档此处

从那一页

泄漏插件的早期版本发出了非名称空间的openopencloseclosed个事件,但这些事件已被名称空间的open.fndtn.showpen.fnddn.show、close.fndtn.exhow事件所取代。当Foundation 5.4发布时,将完全反对使用无名称空间的事件。

因此,根据您使用的reveal.js的版本,似乎有一些事件可以挂钩。

在该页面中,以下是用于挂接打开的事件的片段:

$(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
    var newText = $('.myText').text().replace("Change me", "I have been changed");
    $('.myText').text(newText );
});

编辑添加-对于旧版本,我相信这是挂接事件的方法:

$('#myModal').bind('reveal:open', function () {
    var newText = $('.myText').text().replace("Change me", "I have been changed");
    $('.myText').text(newText );
});

"Change me"将是.myTexttext节点children,或者CCD_ 4在CCD_?此外,$("*")将选择htmlbody元素,将调用时的htmlbody都更改为.text()

尝试

$("body *").each(function () { 
    if ($(this).children(":contains('Change me')")) { 
      $(this).text($(this).text().replace("Change me", "I have been changed"));
  } 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="myModal" class="reveal-modal" style="visibility: visible">
<div class="my-modal-content">
<div class="myText">Change me</div>
<div class="myText">Do not change me</div>
</div>
</div>