我是Bootstrap和jquery的新手,但我遇到了很大的问题,没有找到答案。
情况: 我有一个文本,里面也有工具提示和弹出框。通过弹出框,我显示了一个输入字段和一个按钮。按下按钮后,“工具提示标题”将更改为输入值。这可行。但是...我无法销毁并重新初始化工具提示,因此它不会显示新标题。
代码:
$('.note').each(
function() {
$(this).popover({
placement: 'auto',
html: true,
content: returnNoteInput($(this), $(this).attr("tooltip-title"), $(this).attr("input")),
title: "Jegyzet módosítása"
})
$(this).tooltip({
placement: 'bottom',
title: $(this).attr("tooltip-title")
})
});
function returnNoteInput(inputValue, inputTarget) {
eredmeny = "<input type=\"text\" value=\"" + inputValue + "\"></input>";
eredmeny += "<button onclick=\"setValue(this, '" + inputTarget + "')\")>módosítás</button>"
return eredmeny;
}
function setValue(ele, targetId) {
document.getElementById(targetId).value = ele.previousElementSibling.value;
noteElement = document.getElementById(targetId).nextElementSibling;
noteElement.setAttribute("tooltip-title", ele.previousElementSibling.value);
}
因此一切正常(我可以看到工具提示的标题发生了变化),但无法重新初始化工具提示(我没有复制尝试,因为它没有成功)。
编辑:注意:我还有另一个输入字段,只是为了查看它是否正常工作。
感谢您的帮助!
答案 0 :(得分:0)
我找到了解决方法:
function setValue(ele, targetId){
document.getElementById(targetId).value=ele.previousElementSibling.value;
noteElement= $('#'+targetId).next();
noteElement.attr("tooltip-title",ele.previousElementSibling.value);
noteElement.tooltip("destroy");
noteElement.popover("destroy");
setTimeout(function() {
noteElement.tooltip({placement : 'bottom',title : noteElement.attr("tooltip-title")})
noteElement.popover({placement : 'auto',html:true,content: returnNoteInput(noteElement.attr("tooltip-title"),noteElement.attr("input")), title :"Jegyzet módosítása"})
}
,1000)
}