简体   繁体   English

我如何把这个jQuery变成javascript?

[英]How do i turn this jQuery to javascript?

I have a facebook connect button on this site here is the code 我在这个网站上有一个facebook连接按钮,这里是代码

 <fb:login-button onlogin="javascript:jfbc.login.login_button_click();"
 perms="email,publish_stream,user_about_me,user_hometown,user_location,user_birthday,user_religion_politics,user_interests,user_activities,user_website" 
size="medium" v="2"><a class="fb_button fb_button_medium">
<span class="fb_button_text"\>Login With Facebook</span></a></fb:login-button>

and i want to trigger this button with a javascript call and doing research i found this jquery that seems that it would do the trick (havent tested though) and i was wondering if there is an equivelent javascript or mootool because jquery is not installed. 我想通过javascript调用触发此按钮并进行研究我发现这个jquery似乎它会做的伎俩(虽然没有经过测试)我想知道是否有一个平等的javascript或mootool因为没有安装jquery。 I can install it if i cant find a solution. 如果我找不到解决方案,我可以安装它。 Or if anyone has another idea on how to trigger this facebook button 或者,如果有人对如何触发此Facebook按钮有另一个想法

$("fb\:login-button").trigger("click");

您应该能够只调用内联调用的相同代码:

jfbc.login.login_button_click();

There are two ways to "trigger" a listener: 有两种方法可以“触发”监听器:

  1. call it directly (eg element.onclick() ) 直接调用它(例如element.onclick()
  2. dispatch an event into the DOM that the listener will respond to 将事件分派到侦听器将响应的DOM中

The trouble with the first method is that it doesn't replicate a bubbling event so the listener may not work as intended (eg there is no associated event object or bubbling, the listener's this keyword may not be correctly set). 与第一种方法的问题在于,它不复制冒泡事件,从而预期听者可能不工作(例如,没有相关联的事件对象或起泡,听者的关键字可能不被正确地设置)。

The trouble with the second is that some browsers will not allow programatically dispatched events to do certain things (click on links for example). 第二个问题是某些浏览器不允许以编程方式调度事件来执行某些操作(例如,单击链接)。 Also, in some browsers you have to use the W3C dispatchEvent and in others the Microsoft fireEvent . 此外,在某些浏览器中,您必须使用W3C dispatchEvent,而在其他浏览器中则使用Microsoft fireEvent

So unless the listener has been designed specifically to work with one method or the other and is called appropriately, your chances of triggering the listener successfully are quite low. 因此,除非侦听器专门设计为使用一种方法或另一种方法并且被正确调用,否则成功触发侦听器的可能性非常低。

PS. PS。 Some libraries provide their own event system, with custom events and bubbling of otherwise non-bubbling events, but in that case you have to set and trigger the listener using that library, otherwise it will probably not respond to either of the above methods. 有些库提供了自己的事件系统,自定义事件和非冒泡事件的冒泡,但在这种情况下,您必须使用该库设置和触发侦听器,否则它可能不会响应上述任何一种方法。

I ran into this tonight, absolutely positioned a new button image over the iframe, and was planning on using pointer-events:none to pass through and click the iframe, but I was looking for a cross-browser solution, here you go. 我今晚遇到了这个问题,绝对在iframe上放置了一个新的按钮图像,并计划使用指针事件:无法通过并点击iframe,但我一直在寻找跨浏览器的解决方案。

jQuery('.button_fb_connect').live('click', function(){  FB.login() })

Your simply running the js function FB.login() after clicking your new element, obviously you can use whatever event you want. 单击新元素后,您只需运行js函数FB.login(),显然您可以使用您想要的任何事件。

Thats in jQuery of course, but thats the function you want, not just a simple click event trigger. 那当然是jQuery,但这就是你想要的功能,而不仅仅是一个简单的点击事件触发器。

I suppose it would be something like 我想它会是这样的

document.getElementsByTagName("fb\:login-button")[0].click();

I'm sure that would work very well with a "normal" DOM element that handles the click event; 我确信使用处理click事件的“普通”DOM元素会很好用; however, I'm not entirely sure it will work in all browsers with the fb:login-button element shimmed into HTML. 但是,我并不完全确定它可以在所有浏览器中使用fb:login-button元素填充到HTML中。 You'll have to let me know. 你必须告诉我。

看起来你应该能够做到:

document.body.getElementsByTagName("fb\:login-button")[0].click();

It looks like you want a namespaced element selector, so you should use: 看起来你想要一个命名空间元素选择器,所以你应该使用:

document.getElementsByTagNameNS('fb', 'login-button')[0].click();

The : is the namespace separator. :是命名空间分隔符。

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

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