我使用 jQuery .replaceWith()
插入新的 DOM 内容。所有内容都将被替换,但 title 的值不绑定(bind)。
我试过下面的代码,但工具提示只显示 {{descriptions.title}}
而不是应该显示的文本。
这是我的代码:
$scope.showDescription = function(descriptions) {
$("#description").find('span#header').replaceWith("<span id='header' class='mleft' title='{{descriptions.title}}'>" + descriptions.name + " - " + descriptions.title + "</span>");
}
我希望工具提示显示 descriptions.title 值而不仅仅是 {{descriptions.title}}
最佳答案
您只需添加字符串 {{description.title}}
作为您的标题,您需要添加变量本身:
$scope.showDescription = function(descriptions) {
$("#description").find('span#header').replaceWith("<span id='header' class='mleft' title='" + description.title + "'>" + descriptions.name + " - " + descriptions.title + "</span>");
}
编辑: 在我看来更好的方法是不在这里使用 replaceWith 而只是更改所需的属性:
$scope.showDescription = function(descriptions) {
$("#description").find('span#header').attr("title",description.title).html(descriptions.name + descriptions.title);
}
这样你就可以改变html本身而不需要适配JS。
关于javascript - 无法使用 replaceWith() 将值绑定(bind)到工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56897366/