javascript - 将 jQuery 转换为 Mootools

标签 javascript jquery mootools

我有一些 jQuery 代码,可以很好地在新窗口中打开外部链接,尽管我遇到了 Joomla 网站和 jQuery 的兼容性问题。我过去遇到过这个问题,解决它的最简单方法是使用 Joomla 系统 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>

有人可以帮我转换上面的代码吗?

再次,Mootools 已通过系统插件启用。

最佳答案

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

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');

关于javascript - 将 jQuery 转换为 Mootools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4975124/

相关文章:

JavaScript : Jump to method definition using eclipse

javascript - 如何在 jasmine 中测试 $http 服务

javascript - 使用 JS (jQuery) 从 JSON 对象创建无序列表

javascript - 仅当ajax调用完成时才在函数中返回值吗?

javascript - 优雅降级是否适用于所有事物?对于每个 javascript 和 javascript 框架功能?

javascript - 更新 Salesforce 案例信息

javascript - 输入栏在几秒钟后消失

javascript - 菜单动画意外延迟

jQuery Datatables 插件不保存状态cookie?

javascript - IE 和 Chrome 上的 MooTools 问题