怎么了?

时间:2013-03-22 15:42:34

标签: javascript html

我创建了一个包含一些Javascript代码的页面:

    function createNewWindow () {
      var userName = document.getElementById('user_name').value;
      var newPage = "<html><head><title>";
      newPage += userName;
      newPage += "</title></head><body>";
      newPage += "<p>Hello " + userName;
      newPage += "</p></body></html>";
      var j = window.open('');
     j.document.write(newPage);
     j.document.close();
     }

现在,Dreamweaver说线路上有一个错误:

  var userName = document.getElementById('user_name').value
  var newPage = "<html><head><title>"

我没有看到错误,我搜索了整个互联网。有人来帮我吗?

4 个答案:

答案 0 :(得分:1)

您的代码在语法上是正确的。如果DW抱怨,那就是缺少分号:

function createNewWindow() {
    var userName = document.getElementById('user_name').value; // semi-colon here
    var newPage = "<html><head><title>"; // semi-colon here
    newPage += userName;
    newPage += "</title></head><body>";
    newPage += "<p>Hello " + userName;
    newPage += "</p></body></html>";
    var j = window.open(''); // semi-colon here
    j.document.write(newPage);
    j.document.close();
}

答案 1 :(得分:0)

也许你错过了分号:

var userName = document.getElementById('user_name').value
var newPage = "<html><head><title>"
var j = window.open('')

不是吗?

是否适用于:

var userName = document.getElementById('user_name').value;
var newPage = "<html><head><title>";
var j = window.open('');

答案 2 :(得分:0)

你错过了丢失的分号

var userName = document.getElementById('user_name').value;
var newPage = "<html><head><title>";

答案 3 :(得分:0)

您忘了放;

 var userName = document.getElementById('user_name').value;
 var newPage = "<html><head><title>";