Javascript 将jQuery转换为Mootools

Javascript 将jQuery转换为Mootools,javascript,jquery,mootools,Javascript,Jquery,Mootools,我有一些jQuery代码,可以很好地在新窗口中打开外部链接,尽管我遇到了Joomla站点和jQuery的兼容性问题。我以前遇到过这个问题,解决这个问题最简单的方法是使用Joomla system Mootools库 以下是我需要转换为Mootools的jQuery脚本: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></sc

我有一些jQuery代码,可以很好地在新窗口中打开外部链接,尽管我遇到了Joomla站点和jQuery的兼容性问题。我以前遇到过这个问题,解决这个问题最简单的方法是使用Joomla system Mootools库

以下是我需要转换为Mootools的jQuery脚本:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>         
<script type="text/javascript">                                         
   $(document).ready(function() {
      $('a[href^="http://"]').filter(function() {return this.hostname && this.hostname !== location.hostname;}).attr('target', '_blank');
   });                     
</script>

$(文档).ready(函数(){
$('a[href^=“http://”).filter(函数(){返回this.hostname&&this.hostname!==location.hostname;}).attr('target','u blank');
});                     
有人能帮我转换上面的代码吗


再一次,Mootools已经通过一个系统插件启用了。

我对Mootools不是很熟悉,但是你试过类似的方法吗

$('a').each(function(el){ 
    /* check el.href and if test is true => */ 
    el.set('target','_blank')}
);
Snipplr.com:


。。。实际上,你甚至不需要mootools,如果你担心冲突,你可以用普通javascript来实现。

我对mootools不太熟悉,但你试过类似的方法吗

Snipplr.com:


。。。实际上,你甚至不需要mootools,如果你担心冲突,你可以用普通的javascript来实现。

如果你想再次选择外部链接,你可以设置一个新的伪选择器

Slick.definePseudo('external', function() {
    return this.hostname && this.hostname != window.location.hostname;
});

document.getElements('a[href^=http://]:external').set('target', '_blank');
或者完全像jQuery那样

document.getElements('a[href^=http://]').filter(function(a) {
    return a.hostname && a.hostname != window.location.hostname
}).set('target', '_blank');

如果您想再次选择外部链接,可以设置一个新的伪选择器

Slick.definePseudo('external', function() {
    return this.hostname && this.hostname != window.location.hostname;
});

document.getElements('a[href^=http://]:external').set('target', '_blank');
或者完全像jQuery那样

document.getElements('a[href^=http://]').filter(function(a) {
    return a.hostname && a.hostname != window.location.hostname
}).set('target', '_blank');

您可以使用更好的名称空间。请查看中的
noconflict
。在jQuery中声明
document.ready
事件的最佳方法如下:
jQuery(函数($){…这里的代码…})
因为它将在函数上下文中将jQuery别名为
$
。因此,此代码将target=“\u blank”添加到所有锚定标记中,这些锚定标记的href属性包含一个URL,该URL包含的主机名与当前提供页面的主机名不同?或tl;dr:在新窗口中打开外部站点。对吗?很可能是重复的她使用joomla Too你可以使用更好的名称空间。在jQuery中声明
document.ready
事件的最佳方法如下:
jQuery(函数($){…这里的代码…})
因为它将在函数上下文中将jQuery别名为
$
。因此,此代码将target=“\u blank”添加到所有锚定标记中,这些锚定标记的href属性包含一个URL,该URL包含的主机名与当前提供页面的主机名不同?或tl;dr:在新窗口中打开外部站点。是吗?很可能重复是的,她使用joomla tooThanks Box9我在我的iphone XD上谢谢Box9我在我的iphone XD上第一个选项只在Mootools 1.3中有效,而第二个选项在Mootools 1.2和1.3中都有效第一个选项只在Mootools 1.3中有效,而第二个选项在Mootools 1.2和1.3中都有效