gpt4 book ai didi

javascript - 动态更改工具提示文本 (tippy.js)

转载 作者:行者123 更新时间:2023-11-28 17:41:45 27 4
gpt4 key购买 nike

我正在使用tippy.js 在 asp.net mvc 应用程序中生成工具提示。我试图根据另一个元素(下拉列表)动态更改工具提示的文本。我遇到的问题是“旧”工具提示显示在彼此之上。

这是我的代码(简化):

$(document).on('change', '.partyStatus', function (event) {
event.preventDefault();
event.stopImmediatePropagation(); //stops propagation of click event to other element having the same ID

if (this.value == 5) //Visitor => no autocomplete: free text...
{
partyNameInput.className = "form-control partyName tip";
partyNameInput.title = "Please enter the visitor name.";
tooltip('.tip', 'ehs');
}
else {
partyNameInput.className = "form-control autocomplete_party partyName tip";
partyNameInput.title = "Type in the first letter of a surname, and pick the person from the list.";

tooltip('.tip', 'ehs');
}

});

工具提示功能:

function tooltip(selector, userTheme) {
tippy(selector, {
theme: userTheme,
position: 'right',
animation: 'scale',
duration: 600
})
}

最佳答案

您需要将dynamicTitle选项设置为true。

tippy(selector, {
theme: userTheme,
position: 'right',
animation: scale,
dynamicTitle: true
})

然后可以更改元素的onClick或onHover的title属性

element.addEventListener('click', function() {
this.setAttribute('title', 'New tooltip title here!');
})

来源 TippyJS 文档:https://atomiks.github.io/tippyjs/

关于javascript - 动态更改工具提示文本 (tippy.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47776512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com