单击时按钮不会改变其位置

Chu*_*hun 0 html javascript css

我在这做错了什么?我怎样才能做到这一点?http://jsfiddle.net/qUjDa/

如果我单击按钮的右侧或按钮下方,按钮仅移动,但是如果我单击按钮没有任何反应,我希望它在我单击它的右侧时移动.我是javascript的新手,所以我不知道如何做到这一点.

这是代码:

HTML

<div class="button" id="button">
    <iframe src="http://www.facebook.com/plugins/like.php?href=https://www.facebook.com/FacebookDevelopers&amp;layout=button_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60px; height:21px; position: relative;" allowTransparency="true"></iframe>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.button.move{margin-left:50px;}
Run Code Online (Sandbox Code Playgroud)

JS

var d = document.getElementById("button");
d.addEventListener('click',function(){
    d.className = d.className + " move";
});
Run Code Online (Sandbox Code Playgroud)

mea*_*gar 6

iFrame中的点击事件不会冒出iFrame.无论如何,你实际上无法做你正在做的事情,把一个iframe放在一个按钮里面.那是无效的.按钮内不能存在iframe.

您无法使用vanilla jQuery来检测某人是否与Facebook Like按钮进行交互.您需要使用Facebooks API:

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0