dimanche 1 février 2015

Is a button clicked if statement possible?

I am using Google's Feed API to parse a blog feed. It works flawlessly. Currently, I can make the code show the entire blog post, or just a snippet of it. I want it to show a snippet, but when you click on "Show More" it shows the rest of the blog post.


Here is the code to show the entire post: google.load("feeds", "1"); google.setOnLoadCallback(showFeed);



function showFeed() {
var feed = new google.feeds.Feed("http://ift.tt/15Dkh57");
feed.setNumEntries(1);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("BlogFeed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var li = document.createElement("div");
li.innerHTML = "<h2>" + entry.title + "</h2>";
li.innerHTML += '<p>' + entry.content + '</p>';
container.appendChild(li);
}
}
});
}


Here is the code to show a snippet of the code: google.load("feeds", "1"); google.setOnLoadCallback(showFeed);



function showFeed() {
var feed = new google.feeds.Feed("http://ift.tt/15Dkh57");
feed.setNumEntries(1);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("BlogFeed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var li = document.createElement("div");
li.innerHTML = "<h2>" + entry.title + "</h2>";
content = entry.content.replace(new RegExp('<br.*$'), '');
li.innerHTML += '<p>' + content + '</p>';
container.appendChild(li);
}
}
});
}


I have tried adding another function inside the current one, but I'm pretty sure you can't do that, it didn't work regardless. I know you can add an if statement inside of another if statement.


Aucun commentaire:

Enregistrer un commentaire