为什么我的输出不显示

时间:2017-08-07 16:37:33

标签: javascript php jquery html ajax

为什么我的输出(刷新值)没有显示

function myFunction() {
  $a = document.getElementById("examplehtml").value;
  document.write("<big><bold>");
  document.write($a);
  document.write("</bold></big>");
  $b = document.getElementById("refresh").value;
  document.write('<meta http-equiv="refresh" content="');
  document.write($b);
  document.write('"/>');

}
<form action="javascript:myFunction()" method="get">
  <input name="refresh" value="60" type="text" id="refresh">
  <input name="examplehtml" value="i am is output from input examplehtml, but my input refresh is blank" type="text" id="examplehtml">
  <input type="submit" value="ENTER ">
</form>

显示来自examplehtml的值的结果,但是刷新的值为空白

2 个答案:

答案 0 :(得分:0)

编辑:在输入框中输入网站名称,点击 E N T E R 。它会将您重定向到该网站。

function myFunction(){
  url = document.getElementById('refresh').value;
  window.location.href = url;
}
<input placeholder="write url here" type="text" id="refresh">
<button onclick="myFunction()">E N T E R</button>

编写https://stackoverflow.com进行测试。

答案 1 :(得分:-2)

JavaScript中的字符串连接是使用+运算符完成的。 你可以用这样的东西实现你想要的东西:

function myFunction(){
    var $c= document.getElementById("refresh").value;
    document.write('<meta http-equiv="refresh" content="'+$c+'"/>');
}

您还必须使用var关键字声明变量。

相关问题