【问题标题】:jquery not working in mobile environment: some links are not changing when I open in Android browserjquery 在移动环境中不起作用:当我在 Android 浏览器中打开时,某些链接没有改变
【发布时间】:2014-08-27 13:28:07
【问题描述】:

我正在尝试在 Android 中打开一个网站,所有代码都适用于桌面,但是当我在 Android 浏览器中打开时,某些链接没有改变。

$( document ).ready(function() {

    $('a').each(function(i,link){
        var reg = /(http:\/\/example.com\/)(.*)/
        var newlink = link.href.replace(reg, 'http://m.example.com/$2')
        link.href = newlink;

    });

});

我正在替换网页中的所有链接。是否需要为 Android 实现任何不同的代码?

【问题讨论】:

    标签: javascript php android jquery


    【解决方案1】:

    您可以尝试使用 jquery attr 更改 href,使用它来引用对象

    $( document ).ready(function() {
    
           $('a').each(function(){
             var reg = /(http:\/\/example.com\/)(.*)/
             var href = $(this).attr("href");
             var newlink = href.replace(reg, 'http://m.example.com/$2');
    
             $(this).attr("href",newlink);
    
           });
    
    });  
    

    【讨论】:

      猜你喜欢
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多