源代码中的JavaScript代码无法反映实际执行的代码 [英] JavaScript code in source doesn't reflect code that is actually executed

查看:113
本文介绍了源代码中的JavaScript代码无法反映实际执行的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaScript代码似乎可以正常运行.但是,当我在Chrome中查看源代码"时,它与实际执行的javascript不同.

My javascript code appears to work as it's supposed to. However, when I 'view source' in Chrome, it disagrees with the javascript that is actually executed.

这是我的代码:

<?php
    $_SESSION['new'] = "blue";
    if (!isset($_SESSION['old'])) { $_SESSION['old'] = "blue"; }
        echo '<script type="text/javascript">
            $(document).ready(function() {
                changeCol("'.$_SESSION["old"].'","'.$_SESSION["new"].'");
            });
          </script>';
    $_SESSION['old'] = "blue";
?>    

前一页中的

$_SESSION['old']="green".该代码应该调用changeCol("green","blue"),然后设置$_SESSION['old']="blue".

$_SESSION['old']="green" from the previous page. The code is supposed to call changeCol("green","blue"), and then set $_SESSION['old']="blue".

事实上,这两种情况都会发生,所以我的代码按设计的方式工作,但是,如果我查看源代码,它表示为changeCol("blue","blue").这很奇怪,因为如果在changeCol()中,我将传递的变量写到console.log,则得到green, blue.

In fact, both of these things happen, so my code works as it's designed, but if I view source, it says changeCol("blue","blue"). This is strange, because if in changeCol() I write the passed variables to console.log, I get green, blue.

那么,如果它正在调用changeCol(green,blue),为什么在查看源代码时却说changeCol(blue,blue)?

So if it's calling changeCol(green,blue) why does it say changeCol(blue,blue) when I view source?

推荐答案

查看源代码时,您可能正在提出其他请求.您的会话变量将被重置.

When you view the source, you're probably making an additional request. Your session variable will be reset.

如果您使用的是Chrome或Firefox,则可以打开Web开发工具或Firebug并检查实际的DOM树. (这在脚本动态添加内容的情况下也很有用.)

If you're using Chrome or Firefox — which you should be — you can open up either the Web Developer Tools or Firebug and examine the actual DOM tree. (This is also pretty useful in situations where a script has added content dynamically.)

这篇关于源代码中的JavaScript代码无法反映实际执行的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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