<script>已加载但在chrome源中不可见

时间:2016-09-22 10:04:08

标签: javascript html

在下面的代码片段中,如果我注释空脚本标记,则在chrome dev工具源选项卡中看不到main.js,但在网络选项卡中,我可以看到对main.js的请求成功。

&#xA;&#xA;
 &lt;!doctype html&gt;&#xA;&lt; html&gt;&#xA;&lt; head&gt;&#xA; &lt; title&gt; Typescript Project&lt; / title&gt;&#xA; &LT;脚本&GT;&#XA; window.onload = function load(){&#xA;的console.log(用户);&#XA; };&#XA; &lt; / script&gt;&#xA;&lt; / head&gt;&#xA;&lt; body&gt;&#xA;&lt; script src =“main.js”/&gt;&#xA;&lt;! - 评论在脚本标记下面打破代码 - &gt;&#xA;&lt; script&gt;&lt; / script&gt;&#xA;&#xA;&lt; / body&gt;&#xA;&lt; / html&gt;&#xA;& #xA;&#xA; // main.js&#xA; function greeter(person){&#xA;返回“Hello,”+ person;&#xA;}&#xA; var user =“Jane User”;&#xA; document.body.innerHTML = greeter(user);&#xA;  
&#xA;&#xA;

有人可以解释一下这种行为。感谢

&#XA;

4 个答案:

答案 0 :(得分:1)

<script src="main.js"/>

不是有效的html标记。

看起来你正在深入挖掘它。

不同的浏览器处理无效的HTML标记的方式不同。

那么我该说什么,请遵循规范。

答案 1 :(得分:0)

像这样关闭脚本标记<httpRuntime targetFramework="4.5.1" requestValidationMode="2.0" /> <pages validateRequest="false" />

答案 2 :(得分:0)

像这样写

func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: URLAuthenticationChallenge) {
}

func connection(connection: NSURLConnection, didReceiveResponse:URLResponse)
{
}

func connection(connection: NSURLConnection, didReceiveData data: NSData) {
}

func connection(connection: NSURLConnection, didFailWithError error: NSError) {
    print("Connection Failed")
}


func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge) {
    //sanju swift3 160922-- re verify 

//        let myCredential = URLCredential(forTrust: challenge.protectionSpace.serverTrust!)
   //        challenge.sender!.useCredential(myCredential, forAuthenticationChallenge: challenge)
}

func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: URLProtectionSpace) -> Bool {
    return true
}
func URLSession(session: URLSession, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential) -> Void) {

    let protectionSpace = challenge.protectionSpace

    let theSender = challenge.sender

    if protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {

        if let theTrust = protectionSpace.serverTrust{

            let theCredential = URLCredential(trust: theTrust)

            theSender?.use(theCredential, for: challenge)

            return
        }
    }

    theSender?.performDefaultHandling!(for: challenge)

    return
}

因为

<!doctype html>
 <html>
<head>
<title>Typescript Project</title>

 </head>
  <body>
  <script src="main.js"></script>

答案 3 :(得分:-1)

<!doctype html>
<html>
<head>
    <title>Typescript Project</title>
    <script>
        window.onload = function load() {
            console.log(user);
        };
    </script>
</head>
<body>
<script src="main.js" ></script> <!--changed-->
<!--comment the below script tag to break code-->
<script></script>

</body>
</html>

<script> <!--changed-->
// main.js
function greeter(person) {
    return "Hello, " + person;
}
var user = "Jane User";
document.body.innerHTML = greeter(user);
</script><!--changed-->