gpt4 book ai didi

javascript - jquery多行文本问题

转载 作者:行者123 更新时间:2023-11-28 04:24:49 25 4
gpt4 key购买 nike

我有一个里面有文字的div:

<div>A description of dreamstill. It is a music site that is social and other stuff where you cando this and that and pretty much anything that your heart allows. This is probably as long as the description will get.</div>

然后我提取文本并将其作为 data-url 属性粘贴到图像上:

var desc = div.text();
div.replaceWith('<img class="center" src='+url+' data-desc=' + desc + ' />');

问题是图像是这样生成的:

<img class="center" src="http://featherfiles.aviary.com/2011-09-09/aae3b22a952841cd9c0d6a26a5867325.png" data-desc="A" description="" of="" dreamstill.="" it="" is="" a="" music="" site="" that="" social="" and="" other="" stuff="" where="" you="" cando="" this="" pretty="" much="" anything="" your="" heart="" allows.="" probably="" as="" long="" the="" will="" get.="">

我在这里做错了什么?

最佳答案

问题是您缺少标签中值周围的引号,但您不能只添加引号,因为如果描述文本中有引号,引号仍然会中断。

相反,试试这个。

var desc = div.text();
div.replaceWith(
$('<img />', {
"class": "center",
"src": url,
"data-desc": desc
})
);

关于javascript - jquery多行文本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7411929/

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