Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript脚本隐藏在源代码视图中_Javascript_Html - Fatal编程技术网

javascript脚本隐藏在源代码视图中

javascript脚本隐藏在源代码视图中,javascript,html,Javascript,Html,例如,为什么脚本标记和内容不显示在div标记中 我有以下代码: <div> <!-- BEGIN: YTV Syndicate script --> <!-- Edit Section--> <script type="text/javascript"> alert('hello!'

例如,为什么脚本标记和内容不显示在div标记中

我有以下代码:

<div>
                    <!-- BEGIN: YTV Syndicate script -->
                    <!-- Edit Section-->
                    <script type="text/javascript">
                        alert('hello!'); //check if scripts actually works
                        var YTVSYND = {}
                        YTVSYND.key = 'xxx';
                        YTVSYND.template = {}
                        YTVSYND.template.name = 'ytv'
                        YTVSYND.template.size = 'size300x250'
                        YTVSYND.soc = '<%= Model.Code %>';
                        YTVSYND.type = 'career';
                    </script>
                    <!-- END: EDIT -->
                    <!-- === DO NOT EDIT BELOW=== -->
                    <script type="text/javascript">
                        var ytvSyndUrl = (location.protocol == 'https:') ? 'https://' : 'http://';
                        ytvSyndUrl += 'syncdn.youniversitytv.com/synapi/embed/ytv-embed-api.js';
                        ytvSyndUrl = "/Scripts/ytv-embed-api.js"
                        var str = "<scr" + "ipt type='text/javascript' src='" + ytvSyndUrl + "'>";
                        str += "<";
                        str += "\/scr" + "ipt>";

                        var script = document.createElement('script');
                        script.type = 'text/javascript';
                        script.src = ytvSyndUrl;

                        $("#fgm").html(str)
                    </script>
                    <!-- EOF: YTV Syndicate script -->
                    </div>

警惕(“你好!”)//检查脚本是否实际工作
var YTVSYND={}
YTVSYND.key='xxx';
YTVSYND.template={}
YTVSYND.template.name='ytv'
YTVSYND.template.size='size300x250'
YTVSYND.soc='';
YTVSYND.type='career';
var ytvSyndUrl=(location.protocol=='https:')?'https://':'http://';
ytvSyndUrl+=“syncdn.youniversitytv.com/synapi/embed/ytv embed api.js”;
ytvSyndUrl=“/Scripts/ytv-embed-api.js”
var str=“”;
str+=”;
var script=document.createElement('script');
script.type='text/javascript';
script.src=ytvSyndUrl;
$(“#fgm”).html(str)
它只是执行,但当我检查源代码时,它只显示注释

    <!-- BEGIN: YTV Syndicate script -->
    <!-- Edit Section-->
    <!-- END: EDIT -->
    <!-- === DO NOT EDIT BELOW=== -->
    <!-- EOF: YTV Syndicate script -->

没有脚本标签和实际脚本的迹象

注意:这是在jquery模式中,我在普通页面中有相同的脚本,它显示在源代码视图中


查看源代码不是您的解决方案

查看dom是您的解决方案


使用firebug的web developer

当您使用jQuery将一些HTML内容动态加载到DOM中时,它会完全去掉
标记。在大多数情况下,它会计算它们(使用“eval()”,这或多或少是浏览器会做的),但它们在DOM中不可用

您可以在jQuery源代码中看到代码


编辑-注意,我假设您正在动态添加一些HTML。如果您没有这样做,那么
标记将位于DOM中,您可以在Firebug中看到它们,等等。

您使用的是什么浏览器?您如何查看源代码?您是在检查文档视图(使用Firebug或Chrome开发工具)还是实际的源代码,通常通过右键单击页面并选择“查看源代码”选项来显示?这些都不重要,因为jQuery会剥离
块。@mircea。我可以问一下为什么需要在源代码中显示脚本吗?这有什么区别?我想弄清楚它为什么会有这种行为。我的问题是脚本被执行了,但是最后一行“$(“#fgm”).html(str)”覆盖了整个文档,而不仅仅是“fgm”div。