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


 <!doctype html>
< html>
< head>
 < title> Typescript Project< / title>
 <脚本>
 window.onload = function load(){
的console.log(用户);
 };
 < / script>
< / head>
< body>
< script src =“main.js”/>
<! - 评论在脚本标记下面打破代码 - >
< script>< / script>

< / body>
< / html>
& #xA;
 // main.js
 function greeter(person){
返回“Hello,”+ person;
}
 var user =“Jane User”;
 document.body.innerHTML = greeter(user);



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

答案 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-->