禁用jQuery删除javascript标记

时间:2012-10-22 11:24:39

标签: javascript jquery

最好的,

我正在尝试调试我们的CMS(主要是AJAX),但jQuery删除了所有脚本标签,是什么让我无法调试JavaScript,如何禁用此行为?

我以为我会在简单的谷歌搜索后找到它但没有成功:(

谢谢,

修改

我之前的页面:

    <script>
    jQuery(function(){
        inter = null;
    jQuery('#parse').click(function(){
        jQuery('#answer').load(f(),{"POST":jQuery("#POST").val(),"start":((jQuery('#start').val()-1)*10)},function(){
            alert("Burrrnnnnnnn")
            console.log("Laten we is kijken: " + inter);
                clearInterval(inter);
            });
        inter = setInterval(function(){
            jQuery.getJSON("/googlemonster/backend/status-test",function(json){
                setProgressBar(json);
            });


        },200);
        return false;
    });

    });
     function

     function setProgressBar(obj){
        var g;
        jQuery("#progress-bar,#progress-text-alt-wrapper").animate({"width":(((g=obj["%"])==0?1:g)*2) + "px"},{queue:false});
        jQuery("#progress-text,#progress-text-alt").text(obj["%"] + "% " + obj["status"]);
    }
    </script>
    <style>
    #progress-text-alt-wrapper {
        height: 30px;
        position: absolute;
        z-index: 2;
        width: 1%;
        overflow: hidden;
    }

    #progress {
        border: solid black 1px;
        padding: 1px;
        text-align: center;
        height: 20px;
        width: 200px
    }

    #progress-bar {
        background-color: green;
        width: 1%;
        height: 100%;
    }

    .progress-bar-text {
        padding-top: 3px;
        text-align: center;
        width: 200px;
        position: absolute;
    }

    #progress-text {
     color:green;
    }
    #progress-text-alt {
        color:#eee;
    }
    </style>
     Query:
    <input id="POST" type="text" />
    <br>
    Pagina
    <input value="1" id="start"
        type="number" />
    <br>
    <button id="parse">Look</button>
    <div>
        <div id="progress">
            <div id="progress-text-alt-wrapper">
                <div class="progress-bar-text" id="progress-text-alt">0% Nothing</div>
            </div>
            <div class="progress-bar-text" id="progress-text">0% Nothing</div>
            <div id="progress-bar"></div>
        </div>
    </div>
    <div id="answer"></div>

之后的页面
<style>
#progress-text-alt-wrapper {
    height: 30px;
    position: absolute;
    z-index: 2;
    width: 1%;
    overflow: hidden;
}

#progress {
    border: solid black 1px;
    padding: 1px;
    text-align: center;
    height: 20px;
    width: 200px
}

#progress-bar {
    background-color: green;
    width: 1%;
    height: 100%;
}

.progress-bar-text {
    padding-top: 3px;
    text-align: center;
    width: 200px;
    position: absolute;
}

#progress-text {
 color:green;
}
#progress-text-alt {
    color:#eee;
}
</style>
 Query:
<input id="POST" type="text">
<br>
Pagina
<input value="1" id="start" type="number">
<br>
<button id="parse">Look</button>
<div>
    <div id="progress">
        <div id="progress-text-alt-wrapper">
            <div class="progress-bar-text" id="progress-text-alt">0% Nothing</div>
        </div>
        <div class="progress-bar-text" id="progress-text">0% Nothing</div>
        <div id="progress-bar"></div>
    </div>
</div>
<div id="answer"></div>

2 个答案:

答案 0 :(得分:0)

你说得对 - 剥离脚本标签是jQuery的一个特性。您需要使用基本的JavaScript方法。

请参阅:Can't append <script> element

  

首先评估脚本,然后丢弃。

http://api.jquery.com/append/

答案 1 :(得分:0)

经过一些研究后,我最终可以解决问题,感谢这里的人,

我为它制作了一个jQuery的小插件,现在脚本标签没有被删除,但已被执行。

(function($){

    $.fn.loadDebuggable = function(url){

        data = typeof(arguments[1]) == "object"?arguments[1]:{};
        success = arguments[2]||typeof(arguments[1]) == "function"?arguments[1]:function(){};
        return $.ajax(url,{
            "context":this,
            "success":[function(data){
                var div = document.createElement('DIV');
                div.innerHTML = data;
                this[0].innerHTML = "";
                while (div.firstChild) 
                 {
                    this[0].appendChild(div.firstChild);
                    div.removeChild(div.firstChild);
                 };


            },success],
            "type":"GET",
            "data":data
            });
    }
})(jQuery);

谢谢,