http://topic.csdn.net/u/20090724/10/bd017b97-8dc5-4161-80a0-fd3c9c45587d.html
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
</script>
讨论一下为何是a+b=FALSEFALSE这个结果希望有人可以找到document.write的相关文档说明(如果要加分,可以提)
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
</script>
讨论一下为何是a+b=FALSEFALSE这个结果希望有人可以找到document.write的相关文档说明(如果要加分,可以提)
解决方案 »
- window.open()无法弹出窗口(IE6.0)
- insertBefore
- 我想获得<td>里的字符,怎么实现?
- 如何实现在一个文本框输入IP,子网掩码的文本框掩码自动出来,就像windows网络配置那样
- <td onselectstart="javascript:selection.empty();"><input type="text" /></td>怎么使input的选择保持有效?
- 江湖救急~~~关于SCRIPT嵌套
- js字符串问题?v1.avi如何取出1,在线等待
- <A href="javascript:Download('31')---Download是什么意思?
- 关于字符串的问题:
- HTML5实现MP3上传前的预览和播放时长的获取
- Ajax jQuery请求 想在函数中发送ajax请求 并能改变函数返回的布尔值
- 关于window.close()直接关闭而不显示询问信息
b > +' <h2>'
应该是这样吧...
= =,这代码真...
囧啊....
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write("<div>1</div>","<span>2</span>");//document.write(" <h2>a+b=",+add <a,b>+" <h2>");
document.write(" <h2>a+b=");
document.write( +add <a);
document.write( b>+" <h2>"); document.write("<p></p>");document.write(" <h2>a+b="+add(a,b)+" <h2>");
</script>
</head><body>
</body>
</html>
如果""中的内容解析不了输出 false
这个不是应该写为:
document.write(" <h2>a+b=",+add(a,b)+" <h2>");
逗号导致+add先进行表达式转换,再进行字符串的拼接,从而产生错误。
document.write(" <h2>a+b="+add(a,b)+" <h2>");
就应该没事了。
write() 方法可向文档写入 HTML 表达式或 JavaScript 代码。可列出多个参数(exp1,exp2,exp3,...) ,它们将按顺序被追加到文档中。
w3c上看到的
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
先加载第一个逗号前面的
得到<h2>a+b="
在加载第2个逗号前面的
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(+add <a);//不知道这个能不能看成""+obj
alert(add <a)
</script>可以看到第2表达式是false
加上去 就是 false最后加载第3个逗号前面的
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(+add <a);
alert(b>+"<h2>")//我是当成""+"<h2>"来看的
</script>
alert出来还是false所以是"<h2>a+b=" + false +false
就算是不尔也可以加载到页面<script language="javascript" type="text/javascript">
document.write(false);
</script>以上只是个人理解!!!!!!!
document.write(+add <a);//不知道这个能不能看成""+obj
/////////////////////////////////////////////////////
+add<a
+add为NaN (不知道为什么)alert出来的NaN和任何形式的类型比较都为false<script language="javascript" type="text/javascript">
function a(){
alert('a')
}//undefined、null、string、number、boolean和object
alert( NaN<new Date())
alert(NaN<undefined)
alert(NaN<null)
alert(NaN<1)
alert(NaN<false)
alert(NaN<"assdf")
</script>
document.write(
" <h2>a+b=", //输出 <h2>a+b=
+add <a, //+add为NaN,NaN<a为false,//输出false
b>+" <h2>" //+" <h2>"为NaN,b>NaN为false,//输出false
); //输出<h2>a+b=FALSEFALSE
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
document.write("<br/>");//下面这段代码等价于上面的代码
document.write(" <h2>a+b=");
document.write(+add <a);
document.write(b>+" <h2>");
</script>
可惜下面有这样一句:
说明
虽然根据 DOM 标准,该方法只接受单个字符串作为参数。不过根据经验,write() 可接受任何多个参数。
g(f<a,b>);这是两个解释:
g调用函数f<a,b>这是泛型写法。
但是也可以理解成:调用方法签名如下的g函数---g(boolean,boolean)write是无限叠加表达式的函数,以, 分隔。
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write(" <h2>a+b=",+add <<a,b>> +" <h2>");
</script>这样会把add的arguments[0]置“0”THEN:a+b=05
这位兄台天天在用?有相关官方文档吗?
意外的是原帖的代码错误,但竟然能通过
似乎 JScript 对 document.write 做了一些扩展,使用起来更便利,
个人而言,很喜欢这种参数定义方式。
var a = 3, b = 5;
function add(x, y) {
return x + y;
}
document.write(" <h2>a+b=", add(a, b), " <h2>");
</script>
function add(x, y) {
return praseInt(x) + praseInt(y);
}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return x+y;
}
document.write("<div>1</div>","<span>2</span>");//document.write(" <h2>a+b=",+add <a,b>+" <h2>");
document.write(" <h2>a+b=");
document.write( +add <a);
document.write( b>+" <h2>"); document.write("<p></p>");document.write(" <h2>a+b="+add(a,b)+" <h2>");
</script>
</head><body>
</body>
</html>
document.write(" <h2>a+b=");//得出<h2>a+b=
document.write(+add <a); //得出第一个false
document.write(b>+" <h2>"); //得出第二个false<h2>
所以输出结果是你看到的:a+b=falsefalse
拆开输出就是document.write(" <h2>a+b=")
document.write(add <a),这里由于add为NAN所以返回FALSE
document.write(b>+" <h2>"); 这里同样返回FALSE
这样来看,就明白多了
在浏览器里被解释为了document.write(" <h2>a+b=");
document.write(+add <a,b>);
document.write(b>+" <h2>");所以得到的是楼主的答案。
document.write(" <h2>a+b=",+add(a,b)+" <h2>"); 这样写就对喽
为1,+1也就是1,所以1<a,即1<3=false
解二:+" </h2>" 会转换为NaN,也就是b>NaN=false
请注意:document.write(" <h2>a+b=",add <a,b>+" <h2>"); 这里的add前面少了个加号
document.write(" <h2>a+b="+ add(a,b) +" <h2>");
OK~
函数调用 functionName (参数);
document.write一样会遵从js本身的规则。
var a,b;
function plus(a,b){
return a+b;
}
document.write("<h2>"+"a+b="+plus(1,2)+"<h2>");
</script>
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
1、" <h2>a+b=" 是个字符串,直接输出
2、, 是个参数分解符号
3、+add 中add是函数,这里直接输出函数字符串,+是个二元运算,但是没有前面的参数最后返回NaN
4、空格编译时过滤了
5、+add <a 那这个就成了一个比较过程,NaN<3当然是false
6、, 是个参数分解符号
7、b>+" <h2>" 中+" <h2>"又是一个NaN,整个数据又是false
8、所以输出就是....
你可以试试如下代码
<div id=ddd></div>
<script language="javascript" type="text/javascript">
var a=3,b=5;
function add(x,y){
return 3;
return x+y;
}
document.writeln(" <h2>a+b=",+add <a,b>+" <h2>");
document.writeln("<br>");
document.writeln("aaa","bbb");
document.writeln("<br>");
document.writeln(add);
document.writeln("<br>");
document.writeln(1+add);
document.writeln("<br>");
document.writeln(+add);
document.writeln("<br>");
document.writeln(+add <a);
document.writeln("<br>");
document.writeln(+add<a);
document.writeln("<br>");
document.writeln(+" <h2>");
document.writeln("<br>");
document.writeln(b>+" <h2>");
document.getElementById("ddd").innerText = document.body.innerHTML;
</script>
/*相继输出a,b,c三个单词,逗号为分隔号*/
document.write("a","b","c");
/*逗号为分隔号,“<h2>a+b=”为一字符,“add <a”为一
*字符,为算术运算值FALSE;“b>+" <h2>"”为另一运算
*符,为FALSE。其实,最终得到的字符串是:“<h2>a+b=FALSEFALSE”,没有了后面的“</h2>”
*我这样解释,不知道楼主满意不?
**/
document.write(" <h2>a+b=",+add <a,b>+" <h2>");
这里的add既不大于a,也不小于a,而是等于a的(这个我是debug得到的...),所以是false后面的b>+" <h2>" 相当于b>" "这个不等是>还是<,也都是false(原因同样不清楚...)页面没有js报错是肯定的,但是我所说的大于小于的结果,本身也不是很明白,惭愧
NAN转化为布尔就是FALSE
document.write(" a",'b',"c",'d'); 会输出 abcd.
我觉得吧 应该是被解析成了(" <h2>a+b=" , +add) <a (返回false)
和b>(+" <h2>") 也返回false 不知道对不对呢?
document.write(+add < a);
document.write(b > +"<h2>");
document.write("aa","bb","cc"); //输出aabbcc
document.write(" <h2>a+b=",+add <a,b>+" <h2>"); //输出" <h2>a+b="+表达式(+add <a)比较的结果+表达式(b>+" <h2>")比较的结果
alert(+add <a)//false
alert(b>+" <h2>")//false