【发布时间】:2019-05-13 02:23:08
【问题描述】:
function change(){
item = document.getElementById("first");
item.value = "second";
item.id = "second";
}
ob = document.getElementById("first");
ob.addEventListener("click",change);
<input id="first" type="button" value="first">
当你点击输入时,它变成了:
<input id="second" type="button" value="second">
我的要求是编写javascript代码,以便当您单击id为second的输入时,网页会刷新。也就是改变当前输入元素:
<input id="second" type="button" value="second">
进入上一个:
<input id="first" type="button" value="first">
这是我的尝试:
function change(){
item = document.getElementById("first");
item.value = "second";
item.id = "second";
}
ob = document.getElementById("first");
ob.addEventListener("click",change);
function previous(){
document.execCommand('Refresh')
}
ob = document.getElementById("second");
ob.addEventListener("click",previous);
<input id="first" type="button" value="first">
error: Uncaught TypeError: Cannot read property 'addEventListener' of null
at line27.
【问题讨论】:
-
我们没有命令
"Refresh"。请参阅 list of commands ofdocument.execCommandhere。我想你想改用 ``Location reload()` 函数?
标签: javascript html refresh webpage