-1

我用一些 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

4 回答 4

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();
}
于 2013-03-22T15:44:24.410 回答
0

你忘了放;

 var userName = document.getElementById('user_name').value;
 var newPage = "<html><head><title>";
于 2013-03-22T15:44:30.887 回答
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('');
于 2013-03-22T15:43:41.503 回答
0

你错过了缺少的分号

var userName = document.getElementById('user_name').value;
var newPage = "<html><head><title>";
于 2013-03-22T15:43:44.140 回答