我正试图通过模态中的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模态插件的基础文档此处
从那一页
泄漏插件的早期版本发出了非名称空间的open、open,close和closed个事件,但这些事件已被名称空间的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"将是.myText
的text
节点children
,或者CCD_ 4在CCD_?此外,$("*")
将选择html
和body
元素,将调用时的html
和body
都更改为.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>