如何解决使用 Bootstrap
我想使用相同的预先生成的 html 表单模板提交不同的输入数据(它们只是具有不同的变量名称作为标题)。在我的页面上,我有两个按钮,它们具有基本相同的弹出效果。当我点击 submit
(这是 .popover-content
中的按钮时,似乎我提交了两个表单,即使其中一个隐藏了。
function handlePopover (button) {
const id = button.attr('id');
$(document).on('click','#close',function(){
botton.popover('hide');
}
$(document).on('click','#submit',function(){
if(id === 'button1') alert("button1");
else if(id === 'button2') alert("button2");
}
}
我是这样使用这个功能的:
const button1 = $("#button1");
const button2 = $("#button2");
handlePopover(button1);
handlePopover(button2);
可能是因为我添加了这样的监听器$(document).on(...)
。但我不知道如何解决这个问题。当弹出内容被隐藏时,我可以停用监听器吗?提前致谢!
解决方法
我已经想通了。在向提交按钮添加侦听器之前,您需要为弹出按钮添加侦听器。
dimensions = [row["dimensions"][0] for row in json["reports"][0]["data"]["rows"]]
button.on('shown.bs.popover',function() {
// add a listener to the submit button
$(document).on('click','#submit',function(){
if(id === 'button1') alert("button1");
else if(id === 'button2') alert("button2");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。