如何更改已经显示的引导程序弹出窗口的内容? [英] How to change content of a bootstrap popover that has already been displayed?
问题描述
我有一个输入了两次密码的表格.我检查了密码的复杂性和一致性,并在附加到INPUT字段的弹出框中显示适当的错误消息:
I have a form with a password entered twice. I check password complexity and consistency and display appropriate error messages into a popover attached to the INPUT field:
<a href="#" id="aIdPwd2" data-toggle="manual" data-content="The password entered does not match the one previously entered" data-placement="right" href="#" rel="popover">
<input type="password" id="iIdPwd2" class="fmt1" size="60" value=""/>
</a>
使用以下代码:
$("#aIdPwd2").popover({content: msg});
您可以动态选择将要显示的消息.但是一旦显示一次,它将始终保持不变.
You can chose dynamicaly the message that will be displayed. But once it has been displayed once, it will then always remain the same.
我阅读了许多有关此流行问题的文章,并做了很多尝试(将2个不同的popover附加到相同的输入,更改getElementsByClassName("popover-content")中的内部html,销毁并重新创建popover,..) ,但到目前为止没有任何成功.
I read many articles about this popular issue and did try many things (attach 2 different popover to the same input, change the inner html in the getElementsByClassName("popover-content"), destroy and recreate the popover, ..), but without any success so far.
高度赞赏有关如何更改已显示的自举弹出窗口的内容或任何变通方法的解决方案.
A solution on how to change content of a bootstrap popover that has already been displayed or any kind of work-around would be highly appreciated.
推荐答案
document.getElementsByClassName("popover-content")[0].innerHTML = 'something else';
确定这行不通吗?
在此页面上进行了尝试,它可以正常工作.
tried it on this page and it works as expected.
更新:它仅在弹出窗口可见时才起作用,因为在每次mouseover/mouseout事件中都会重新创建/销毁该元素
UPDATE: it will work only if the popover is visible because the element is recreated/destroyed every mouseover/mouseout event
我猜这不是最好的解决方案,但是您可以这样做:
i guess it's not the best solution, but you can do this:
var msg = 'ben123 is not a goddamn password!';
document.getElementById('password').addEventListener('mouseover', function() {
document.getElementsByClassName("popover-content")[0].innerHTML = msg;
});
并在需要时更改msg
这篇关于如何更改已经显示的引导程序弹出窗口的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!