大家: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <input type="button" name="Button" value="Button" onclick="javascript:document.write('123');alert('a');document.write('456');alert('b');document.close();"> </body> </html>结果alert('a')被执行,alert('b')不被执行。我的问题是:为什么程序一直执行到第二个document.write前面的语句,而不是执行完第一个document.write就结束?
1)javascript: 是浏览器的一种行为JavaScript Protocol-------------------------------------------------------------------------------- Specifies that the URL is JavaScript code. Syntaxjavascript:sJScript Possible ValuessJScript Required. Specifies one or more semicolon-separated JavaScript statements. ResAvailable as of Microsoft® Internet Explorer 3.0 or later. ExampleThe following sample demonstrates the use of the JavaScript protocol. <A HREF="javascript:alert('JavaScript Link!');"> JavaScript Link </A> 2) 联想一下这个 在浏览器地址栏输入 javascript:document.writeln('456');document.writeln('123');alert('a');alert('b');document.close(); 查看源文件,你将看到: <HTML><SCRIPT LANGUAGE=javascript>var __w=document.writeln('456');document.writeln('123');alert('a');alert('b');document.close();;if(__w!=null)document.write(__w);</SCRIPT></HTML> 可以想象, 你用javascript:写脚本时 小心被浏览器改造了你的代码
你只可以操作浏览器将静态文本Parse成结构化的东西:DOM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<input type="button" name="Button" value="Button" onclick="javascript:document.write('123');alert('a');document.write('456');alert('b');document.close();">
</body>
</html>结果alert('a')被执行,alert('b')不被执行。我的问题是:为什么程序一直执行到第二个document.write前面的语句,而不是执行完第一个document.write就结束?
是浏览器的一种行为JavaScript Protocol--------------------------------------------------------------------------------
Specifies that the URL is JavaScript code.
Syntaxjavascript:sJScript
Possible ValuessJScript Required. Specifies one or more semicolon-separated JavaScript statements. ResAvailable as of Microsoft® Internet Explorer 3.0 or later.
ExampleThe following sample demonstrates the use of the JavaScript protocol. <A HREF="javascript:alert('JavaScript Link!');">
JavaScript Link
</A>
2)
联想一下这个
在浏览器地址栏输入
javascript:document.writeln('456');document.writeln('123');alert('a');alert('b');document.close();
查看源文件,你将看到:
<HTML><SCRIPT LANGUAGE=javascript>var __w=document.writeln('456');document.writeln('123');alert('a');alert('b');document.close();;if(__w!=null)document.write(__w);</SCRIPT></HTML> 可以想象, 你用javascript:写脚本时
小心被浏览器改造了你的代码
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<input type="button" name="Button" value="Button" onclick="aa()">
</body>
<script>
function aa()
{
document.write('123');
confirm('');
alert('');
alert('');
document.write('456');
document.close();
}
</script>
</html>
我不懂,请解释一下,或给出参考链接。加到50分。
write是document的方法,
button按下后window.document已经不是最初的document而是提交后的document
而由于window对象仍然是最初的window对象它的方法仍可执行。
不知我的理解对不对?