简体   繁体   English

FB Like按钮/ if语句/ innerHTML

[英]FB Like button / if statement / innerHTML

So I'm trying to make it so that when you: press the Facebook like button, the innerHTML of #pChange will change to whatever it may be. 因此,我试图做到这一点,以便在您:按Facebook之类的按钮时,#pChange的innerHTML会更改为任何可能。

I'm guessing there's another way to set the if statement. 我猜还有另一种设置if语句的方法。

Any help would be greatly appreciated. 任何帮助将不胜感激。

var myTest = document.getElementById('likeButton');

if(myTest === true) {
    document.getElementById('pChange').innerHTML="This is a test";
};

http://jsfiddle.net/TobaccoJoe/P7B4t/ http://jsfiddle.net/TobaccoJoe/P7B4t/

You have to handle the click event on the button, so a plain "if statement" won't be enough. 您必须处理按钮上的click事件,因此仅使用“ if语句”是不够的。 Unfortunately, iframes don't allow you to set an "onclick" property. 不幸的是,iframe不允许您设置“ onclick”属性。 The best solution would be to see if Facebook allows you to set a callback on the iframe. 最好的解决方案是查看Facebook是否允许您在iframe上设置回调。

Another way that would work I think would be something like : 我认为另一种可行的方式是:

var myTest = document.getElementById('likeButton');
var thisDocument=document;
var clickHandler = function(event){
     thisDocument.getElementById('pChange').innerHTML="This is a test";
};
myTest.contentDocument.addEventListener("click",clickHandler,false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM