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的相关文档说明(如果要加分,可以提)

解决方案 »

  1.   

    a + b =+add < a
    b > +' <h2>'
    应该是这样吧...
    = =,这代码真...
      

  2.   

    < 和 >  被作为比较符号了..
     囧啊....
      

  3.   

    两个逗号表达式,+add转为数字是nan
      

  4.   

    逗号和<>的问题,不知道怎么解析的
      

  5.   


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

  6.   

    document.write("a","b");相当于document.write("a");document.write("b");
    如果""中的内容解析不了输出 false
      

  7.   

    document.write(" <h2>a+b=",+add <a,b>+" <h2>"); 
    这个不是应该写为:
    document.write(" <h2>a+b=",+add(a,b)+" <h2>"); 
      

  8.   

    document.write(" <h2>a+b=",+add <a,b>+" <h2>"); 由于你的逗号的原因造成了这个结果。
    逗号导致+add先进行表达式转换,再进行字符串的拼接,从而产生错误。
    document.write(" <h2>a+b="+add(a,b)+" <h2>");
    就应该没事了。
      

  9.   

    应该是这样
    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>以上只是个人理解!!!!!!!
      

  10.   

    上面有个地方理解错了
    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>
      

  11.   

    document.write本来就能接收个参数,效果等于输出各个参数转化为字符串后串联的结果
    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
      

  12.   


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

  13.   

    找了一下,终于看到了
    可惜下面有这样一句:
    说明
    虽然根据 DOM 标准,该方法只接受单个字符串作为参数。不过根据经验,write() 可接受任何多个参数。
      

  14.   

    java也有你这样的错误。如下:
    g(f<a,b>);这是两个解释:
    g调用函数f<a,b>这是泛型写法。
    但是也可以理解成:调用方法签名如下的g函数---g(boolean,boolean)write是无限叠加表达式的函数,以, 分隔。
      

  15.   

    没什么好奇的<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>这样会把add的arguments[0]置“0”THEN:a+b=05
      

  16.   

    document.write(exp1,exp2,exp3,...)
    这位兄台天天在用?有相关官方文档吗?
    意外的是原帖的代码错误,但竟然能通过
      

  17.   

    document.write(" <h2>a+b="+add(a,b)+" <h2>"); 
      

  18.   

    arguments 才是问题所在,关键要看方法内部对于 arguments 的检查,
    似乎 JScript 对 document.write 做了一些扩展,使用起来更便利,
    个人而言,很喜欢这种参数定义方式。
      

  19.   

    document.write(NaN<3,5>NaN); 
      

  20.   

    +add => NaN+" <h2>" => NaN
      

  21.   

    如果其中一个表达式为 NaN,返回 false
      

  22.   

    咳....<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>
      

  23.   

    write Method--------------------------------------------------------------------------------Writes one or more HTML expressions to a document in the specified window. 
      

  24.   

    write Method--------------------------------------------------------------------------------Writes one or more HTML expressions to a document in the specified window. 
      

  25.   

      var a = 3, b = 5;
            function add(x, y) {
                return praseInt(x) + praseInt(y);
    }
      

  26.   

    恩 很新的语法没注意过,不过现在明白了原来是按逗号 依次解释的只不过群主看的角度错了我刚开始一看以为JS也出泛型了,原来还是普通的 >,< 的比较
      

  27.   

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

  28.   

    你可以这样输出一下试试:
    document.write(" <h2>a+b=");//得出<h2>a+b=
    document.write(+add <a);    //得出第一个false
    document.write(b>+" <h2>"); //得出第二个false<h2>
    所以输出结果是你看到的:a+b=falsefalse 
      

  29.   

    学过的javascript 全忘了  汗颜啊! 看到这个 ,又去重新看了一部分
      

  30.   

    其实就是docment.write多个参数的那种用法,你分开来看就明白了document.write(" <h2>a+b=",add <a,b>+" <h2>"); 
    拆开输出就是document.write(" <h2>a+b=")
    document.write(add <a),这里由于add为NAN所以返回FALSE
    document.write(b>+" <h2>"); 这里同样返回FALSE
    这样来看,就明白多了
      

  31.   

    document.write(" <h2>a+b=",+add <a,b>+" <h2>"); 
    在浏览器里被解释为了document.write(" <h2>a+b="); 
    document.write(+add <a,b>); 
    document.write(b>+" <h2>");所以得到的是楼主的答案。 
      

  32.   


    document.write(" <h2>a+b=",+add(a,b)+" <h2>");  这样写就对喽
      

  33.   

    楼主的这个逗号和“>”和“<”进行了比较运算,这样的话得出的肯定不是数字啊!只有True 或者 False!
      

  34.   

    不定长参数,这个在javascript中应该是普遍存在的吧.
      

  35.   

    不定长参数,这个在javascript中应该是普遍存在的吧.
      

  36.   

    解一:+add < aadd为一个function也就是一个object,一个object在和比较运算符比较时,会转换为bool值,非空object会转换
    为1,+1也就是1,所以1<a,即1<3=false
    解二:+" </h2>" 会转换为NaN,也就是b>NaN=false
      

  37.   


    请注意:document.write(" <h2>a+b=",add <a,b>+" <h2>"); 这里的add前面少了个加号
      

  38.   

    这句
    document.write(" <h2>a+b="+ add(a,b) +" <h2>"); 
    OK~
    函数调用 functionName (参数);  
      

  39.   

    js 是弱语言类型,如果有数字或是比较运算,也会按照相应的顺序加载数据并进行计算的。
    document.write一样会遵从js本身的规则。
      

  40.   

    <script type="text/javascript">
    var a,b;
    function plus(a,b){
     return a+b;
    }
    document.write("<h2>"+"a+b="+plus(1,2)+"<h2>");
    </script>
      

  41.   

    权威回答
    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>
      

  42.   


    /*相继输出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>"); 
      

  43.   

    document.write(" <h2>a+b=",+add <a,b>+" <h2>"); 这一部分+add <a这里add是方法,所以不会报错,js的方法调用时后面的参数并不严格.
    这里的add既不大于a,也不小于a,而是等于a的(这个我是debug得到的...),所以是false后面的b>+" <h2>" 相当于b>" "这个不等是>还是<,也都是false(原因同样不清楚...)页面没有js报错是肯定的,但是我所说的大于小于的结果,本身也不是很明白,惭愧
      

  44.   

    主要还是JS的自动转换数据类型吧,
    NAN转化为布尔就是FALSE
      

  45.   

    document.write(" <h2>a+b=",+add <a,b>+" <h2>"); " <h2>a+b=" ,   +add <a ,   b>+" <h2>"  是三个表达式。
    document.write(" a",'b',"c",'d');  会输出 abcd.
      

  46.   


    我觉得吧  应该是被解析成了(" <h2>a+b=" , +add) <a  (返回false)
    和b>(+" <h2>") 也返回false  不知道对不对呢?
      

  47.   

    应该等同于document.write(" <h2>a+b=");
        document.write(+add < a);
        document.write(b > +"<h2>");
      

  48.   

    document.write("aa""bb""cc");//报错
    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
      

  49.   

    为什么 +add 会是NaN呢