jQuery添加未显示在视图页面源中 [英] jquery addition is not showing in view page source

查看:91
本文介绍了jQuery添加未显示在视图页面源中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过jQuery更改url的域名,当页面加载时它正在工作,但是当我在查看页面源代码时,没有显示添加内容.

I am changing domain name for url by jQuery, it's working when page is loading but when I am doing view page source the addition is not showing.

我的代码:

$(document).ready(function(){
    var hname= location.hostname;
    var linkRewriter = function(a, b, c) {
        if(hname=="www.somesite.com"){
            $('a[href*="' + a + '"]').each(function() {
                $(this).attr('href', $(this).attr('href').replace(a, b));
            });
        }
        linkRewriter('https://www.somesite1.com/', 'https://www.somesite2.com/'); 
    });
});

推荐答案

之所以没有显示新的URL,是因为浏览器会显示从服务器下载的源.它们显示来自缓存的原始源,或者通过响应查看源"命令重新请求原始源.

The reason it isn't showing the new urls is that browsers show the source as it was downloaded from the server. They show the raw source from cache or by re-requesting it in response to the "view source" command.

如果JavaScript修改了部分源代码,则原始源代码仍将包含原始值.

If JavaScript has modified part of the source, the original source will still contain the original values.

如果要查看当前的,经过修改的页面源代码,请查看浏览器的开发工具:

If you want to take a look at the current, modified, page source, take a look at your browser's development tools:

  • Chrome
  • Firefox
  • IE
  • Safari

在大多数现代浏览器上,如果右键单击选择框,将具有检查"或检查元素"菜单选项,这些选项将打开开发工具并在DOM检查器中导航到该元素.

On most modern browsers, if you right-click the select box, you'll have an "Inspect" or "Inspect Element" menu option that will open the dev tools and navigate to that element in the DOM inspector.

这篇关于jQuery添加未显示在视图页面源中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆