建立博客 - JQuery 动态 post 采集器
Building a Blog - JQuery dynamic post grabber
我正在用 Html/Css/JQuery 建立一个博客,但我碰壁了。
我想根据预先从 link 传入的数字加载不同的博客 Post。例如,如果我有 3 Post,则根据选择的数字加载内容。
这是在 content.js
.
var prepareContent = function (postNumber) {
readTextFile(postNumber);
};
但是,当在另一个 .js
文件中调用 click
时,我不知道如何操作 postNumber
。
这是在 index.js
.
$("#post0").click(function () {
conentPassed = 0;
window.location = "content.html";
});
$("#post1").click(function () {
contentPassed = 1;
window.location = "content.html";
});
我想"pass"一个变量从index.js
变成content.js
。有什么办法吗?谢谢。
我认为正如 ThisClark 指出的那样,也有类似的问题解决方案。
前阵子我遇到了类似的问题,发现 url 的哈希添加有帮助:
window.location = "content.html/#" + contentPassed;
然后在接收端:
postNumber = window.location.href.split("#")[1];
postNumber = Number(postNumber);
这会获取当前的 url,然后使用散列作为拆分器将其拆分为多个部分,这些部分成为一个数组,[1] 为您提供第二部分。第二行是确定它不再是一个字符串。
不知道这是否有帮助?
我正在用 Html/Css/JQuery 建立一个博客,但我碰壁了。
我想根据预先从 link 传入的数字加载不同的博客 Post。例如,如果我有 3 Post,则根据选择的数字加载内容。
这是在 content.js
.
var prepareContent = function (postNumber) {
readTextFile(postNumber);
};
但是,当在另一个 .js
文件中调用 click
时,我不知道如何操作 postNumber
。
这是在 index.js
.
$("#post0").click(function () {
conentPassed = 0;
window.location = "content.html";
});
$("#post1").click(function () {
contentPassed = 1;
window.location = "content.html";
});
我想"pass"一个变量从index.js
变成content.js
。有什么办法吗?谢谢。
我认为正如 ThisClark 指出的那样,也有类似的问题解决方案。
前阵子我遇到了类似的问题,发现 url 的哈希添加有帮助:
window.location = "content.html/#" + contentPassed;
然后在接收端:
postNumber = window.location.href.split("#")[1];
postNumber = Number(postNumber);
这会获取当前的 url,然后使用散列作为拆分器将其拆分为多个部分,这些部分成为一个数组,[1] 为您提供第二部分。第二行是确定它不再是一个字符串。
不知道这是否有帮助?