gpt4 book ai didi

javascript - 符号 (&) 变成 &

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:49:58 25 4
gpt4 key购买 nike

我使用以下代码每 30 秒自动抓取/设置最新的页面标题:

<script type="text/javascript">
setInterval(function() {
var data = "http://mysite.com/mypage.php";
$.get(document.location.toString()).then(function (data){
//find and set the title of the page
document.title = data.match(/<title>(.+)<\/title>/)[1];
});
}, 30000);
</script>

它工作得很好,除了包含 & 符号的标题。这些加载正常,然后在 30 秒后替换为:

&amp;

所以如果页面标题是:

Fun & Games

30秒后,变成:

Fun &amp; Games

谢谢

最佳答案

与其使用正则表达式提取标题,不如尝试询问 DOM 返回页面的标题是什么。问题是,在您的文件中,它是 &,但是一旦解析它就变成了 &

$.get(document.location.toString()).then(function (data){
//find and set the title of the page
document.title = $(data).filter('title').text();
});

关于javascript - 符号 (&) 变成 &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16597082/

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