Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将函数从jQuery(“page>;ul>;li:last>;a>;”)转换。单击()转换为原型_Jquery_Prototypejs - Fatal编程技术网

将函数从jQuery(“page>;ul>;li:last>;a>;”)转换。单击()转换为原型

将函数从jQuery(“page>;ul>;li:last>;a>;”)转换。单击()转换为原型,jquery,prototypejs,Jquery,Prototypejs,我有一个使用jQuery的语句,如下所示: jQuery("#page>ul>li:last>a").click(); 如何在Prototype中做到这一点?Prototype中的选择器与jQuery中的选择器相同。不同之处在于,您必须在prototype中使用$函数,然后迭代每个选定元素: $$('#page>ul>li:last>a')[0].on('click',function(event){ }); $$("#page > ul >

我有一个使用jQuery的语句,如下所示:

jQuery("#page>ul>li:last>a").click();

如何在Prototype中做到这一点?

Prototype中的选择器与jQuery中的选择器相同。不同之处在于,您必须在prototype中使用
$
函数,然后迭代每个选定元素:

$$('#page>ul>li:last>a')[0].on('click',function(event){

 });
$$("#page > ul > li:last > a").each(function(element) {
    eventFire(element, "click");
});
看起来prototype没有像jQuery那样的方法。您可以编写类似于中的函数:


选择器在原型中与jQuery中相同。不同之处在于,您必须在prototype中使用
$
函数,然后迭代每个选定元素:

$$("#page > ul > li:last > a").each(function(element) {
    eventFire(element, "click");
});
看起来prototype没有像jQuery那样的方法。您可以编写类似于中的函数:


OPs post中的结束调用不会创建处理程序,它会触发事件。此外,选择器可能会返回多个
a
@Andrew Whitaker,是的,你是对的,那么对我来说没问题(原型1.7),在Firefox上,OPs post中的结束调用不会创建处理程序,它会触发事件。此外,选择器可以返回多个
a
@Andrew Whitaker,是的,你是对的,那么在Firefox上对我来说很好(原型1.7),如果我使用下面的方法,我将有:$$(“#list>ul>li:last>a”)。每个(函数(元素){element.on('click',函数(e){//alert(e);});所以,我的问题是,我能做到吗?或者这里出了什么问题?@vietean:你发布的jQuery代码没有将事件处理程序绑定到click事件:它会在所选元素上触发click事件。我如何理解trigger和event之间的关系?啊哈,我已经阅读了你的链接,现在我得到了它。谢谢我喜欢你的答案。如果我用你的方式处理下面的问题,我将得到:$$(“#list>ul>li:last>a”)。每个(函数(元素){element.on('click',函数(e){//alert(e);});});所以,我的问题是,我能做到吗?或者这里出了什么问题?@vietean:你发布的jQuery代码没有将事件处理程序绑定到click事件:它会在所选元素上触发click事件。我如何理解trigger和event之间的关系?啊哈,我已经阅读了你的链接,现在我得到了它。谢谢我喜欢你的答案。