我是个JS的新手,请教各位高手一个问题,下面的代码为什么在chrome中不能正常显示结果呢?代码如下:<html>
<head>
<script type="text/javascript">
function disp_prompt()
  {
  var name=prompt("请输入您的名字","Bill Gates")
  if (name!=null && name!="")
    {
    document.write("你好!" + name + " 今天过得怎么样?")
    }
  }
</script>
</head>
<body><input type="button" onclick="disp_prompt()" value="显示提示框" /></body>
</html>

解决方案 »

  1.   


    <html>
    <head>
    <script type="text/javascript">
    function disp_prompt()
      {
      var name=prompt("请输入您的名字","Bill Gates");
      if (name!=null && name!="")
      {
      alert("你好!" + name + " 今天过得怎么样?");
      }
      }
    </script>
    </head>
    <body><input type="button" onclick="disp_prompt()" value="显示提示框" /></body>
    </html>
    很奇怪的是ALERT没有问题。。再看看
      

  2.   

    chrome浏览器中有这个prompt么,加个window.prompt
      

  3.   

    chrome浏览器中有这个prompt么,加个window.prompt
      

  4.   

    加上P标签就好了。<html>
    <head>
    <script type="text/javascript">function disp_prompt() {
        var name = window.prompt("请输入你的姓名", "Bill Gates");
        if (name!=null && name!="")
    {
            window.document.write("<p>你好 " + name + "! 今天过的怎么样?<\/p>");
        }
    }
    </script>
    </head>
    <body><input type="button" onclick="disp_prompt()" value="显示输入框" /></body>
    </html>
      

  5.   


    <html>
    <head>
    <script type="text/javascript">
    function disp_prompt()
      {
      var name=window.prompt("请输入您的名字","Bill Gates")
      if (name!=null && name!="")
      {
    document.open();
    document.write("你好!" + name + " 今天过得怎么样?");
    document.close();
      }
      }
    </script>
    </head>
    <body><input type="button" onclick="disp_prompt()" value="显示提示框" /></body>
    </html>
      

  6.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD><BODY>
    <input type="button" onclick="disp_prompt()" value="显示提示框" /></BODY>
    <script type="text/javascript">
    function disp_prompt()
      {
      var name=prompt("请输入您的名字","Bill Gates")
      if (name!=null && name!="")
      {
      document.write("你好!" + name + " 今天过得怎么样?")
      }
      }
    </script></HTML>XMTL是逐段读代码所以要放在下面,要先读body才能用prompt
      

  7.   

    document.write("你好!今天过得怎么样?");
            //在write后加上下面一句话!!!
    document.close();
    /*  关于document.write()方法还有一点要说明的是它的相关方法document.close()。脚本向窗口(不管是本窗口或其他窗口)写完内容后.必须关闭输出流。在延时脚本的最后一个document.write()方法后面.必须确保含有document.close()方法,不这样做就不能显示图片和表单。并且,任何后面调用的document.write()方法只会把内容追加到页面后,而不会清除现有内容来写入新值。*/参考