gpt4 book ai didi

javascript - 如何获取标题属性作为变量来替换 PrettyPhoto 中的主题标签?

转载 作者:行者123 更新时间:2023-11-28 08:34:50 25 4
gpt4 key购买 nike

我正在尝试将扩展图像的主题标签链接替换为其标题,而不是编号索引。

我已设法从网址中删除不需要的编号,但我不知道如何检索标题。

在编辑 PrettyPhoto javascript 时,我将 SetHashtag 函数更改为:

function setHashtag(){
var title = pp_titles;
if(typeof theRel == 'undefined') return; // theRel is set on normal calls, it's impossible to deeplink using the API
location.hash = theRel + '/'+title+'/';
};

在变量中使用“pp_titles”似乎会从整个图库中提取所有标题并将它们添加到网址的末尾。我只想使用当前图像的标题,但我不确定从哪里检索它。

您可以在此处的任何图像中看到示例:http://www.sghalliday.com/urban2.html

当用户退出图库时,我还会尝试从网址末尾删除主题标签,但目前这并不是什么大问题。

最佳答案

快速解决方案,更改 prettyphoto.js 中的这些行,然后就可以开始了。如果标题为空,URL 看起来会很难看,但仍然可以使用;)

...
...

if(!pp_alreadyInitialized && getHashtag()){
pp_alreadyInitialized = true;

// Grab the rel index to trigger the click on the correct element
hashIndex = getHashtag();
ergec = hashIndex.split("/"); // add this line
hashRel = hashIndex;

//hashIndex = hashIndex.substring(hashIndex.indexOf('/')+1,hashIndex.length-1); // comment this line
//hashRel = hashRel.substring(0,hashRel.indexOf('/')); // comment this line
hashIndex = ergec[ergec.length - 2]; // add this line
hashRel = ergec[0]; // add this line

// Little timeout to make sure all the prettyPhoto initialize scripts has been run.

...
...

function setHashtag(){
if(typeof theRel == 'undefined') return; // theRel is set on normal calls, it's impossible to deeplink using the API
location.hash = theRel + '/' + pp_titles[rel_index] + '/' + rel_index +'/'; // alter this line
};

...
...

关于javascript - 如何获取标题属性作为变量来替换 PrettyPhoto 中的主题标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368228/

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