1 回答
TA贡献1943条经验 获得超7个赞
您需要将获取文本框的值移到提交处理程序中。目前,newItem页面加载时正在设置值,并且永远不会再设置。
var form = document.getElementById('addForm');
form.addEventListener('submit', redirect);
function redirect(e)
{
e.preventDefault();
let newItem = document.getElementById('item').value; // this collects value that I have entered in search box for eg fake facebook or fake insta
if (newItem == 'fakefacebook')
{
window.open('file:///C:/html/index.html');
}
else if (newItem == 'fakeinstagram')
{
window.open('file:///C:/fakeinsta/index.html');
}
}
<form id="addForm">
<p><label for="item">Input the search term:</label><input type="text" id="item">
<p><input type="submit"></p>
</form>
添加回答
举报