gpt4 book ai didi

javascript - 替换为不删除元素

转载 作者:行者123 更新时间:2023-11-30 23:55:22 24 4
gpt4 key购买 nike

这是 html:(示例)

<div class="lblTest well" data-src="001">Label 1</div>

to

<a class="lblTest well" data-src="001" href="#" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom 1" >Label 1</a>

这是js:

$('.lblTest').each(function (i, n) {
var $element = $(this);
$element.replaceWith(function () {
return $('<a/>', {
html: this.innerHTML,
class: this.className,
href: '#',
'data-src':this.('dataSrc'), /// < ???
'data-toggle':'tooltip',
'data-placement':'bottom',
'title':'Tooltip on bottom ' + (i + 1)
});
});
});

此代码不正确:

'data-src':this.('dataSrc'), /// < ???

Fiddle

最佳答案

您的元素中没有 dataSrc 属性。应该是这样

$(this).data("src"),

关于javascript - 替换为不删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61090080/

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